(1)2023年美赛C题Wordle预测问题一建模及Python代码详细讲解
(2)2023年美赛C题Wordle预测问题二建模及Python代码详细讲解
(3)2023年美赛C题Wordle预测问题三、四建模及Python代码详细讲解
(4)2023年美赛C题Wordle预测问题27中文页论文
(1)将2023-3-1的EERIR样本,加入到数据集中,和所有数据集一起预处理和做特征工程。
特征工程中,和问题一第二问中类同的是,提取了’w1’,‘w2’,‘w3’,‘w4’,‘w5’,‘Vowel_fre’,'Consonant_fre’这几个特征,再加上时间特征包括年、月、日、季节、样本序号。
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as snsdf = pd.read_excel('data/Problem_C_Data_Wordle.xlsx',header=1)data = df.drop(columns='Unnamed: 0')data.loc[len(data)] = ['2023-3-1',np.nan,'eerie',np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan]data['Date'] = pd.to_datetime(data['Date'])df =data.copy()df['Words'] = df['Word'].apply(lambda x:str(list(x))[1:-1].replace("'","").replace(" ",""))df['w1'], df['w2'],df['w3'], df['w4'],df['w5'] = df['Words'].str.split(',',n=4).strdfdf['w1'] = df['w1'].map(letter_map)df['w2'] = df['w2'].map(letter_map)df['w3'] = df['w3'].map(letter_map) df['w4'] = df['w4'].map(letter_map)df['w5'] = df['w5'].map(letter_map)df.set_index('Date',inplace=True)df.sort_index(ascending=True,inplace=True)df{‘a’: 1, ‘b’: 2, ‘c’: 3, ‘d’: 4, ‘e’: 5, ‘f’: 6, ‘g’: 7, ‘h’: 8, ‘i’: 9, ‘j’: 10, ‘k’: 11, ‘l’: 12, ‘m’: 13, ‘n’: 14, ‘o’: 15, ‘p’: 16, ‘q’: 17, ‘r’: 18, ‘s’: 19, ‘t’: 20, ‘u’: 21, ‘v’: 22, ‘w’: 23, ‘x’: 24, ‘y’: 25, ‘z’: 26}
(2)统计元音辅音频率
Vowel = ['a','e','i','o','u'] Consonant = list(set(small).difference(set(Vowel)))def count_Vowel(s): c = 0 for i in range(len(s)): if s in Vowel: c+=1 return cdef count_Consonant(s): c = 0 for i in range(len(s)): if s in Consonant: c+=1 return cdf['Vowel_fre'] = df['Word'].apply(lambda x:count_Vowel(x)) df['Consonant_fre'] = df['Word'].apply(lambda x:count_Consonant(x))(3)提取时间特征
df["year"] = df.index.yeardf["qtr"] = df.index.quarterdf["mon"] = df.index.monthdf["week"] = df.index.weekdf["day"] = df.index.weekdaydf["ix"] = range(0,len(data))time_features = ['year','qtr','mon','week','day','ix']df(3)构造数据集
from sklearn.preprocessing import StandardScalerfeatures = ['w1','w2','w3','w4','w5','Vowel_fre','Consonant_fre']+time_featureslabel = ['1 try','6 tries','6 tries','6 tries','6 tries','6 tries','7 or more tries (X)']Trian_all = df[features+label].copy().dropna()X = Trian_all[features]# 标准化ss = StandardScaler()X_1 = ss.fit_transform(X)Y_1= Trian_all[label[0]]Y_2= Trian_all[label[1]]Y_3= Trian_all[label[2]]Y_4= Trian_all[label[3]]Y_5= Trian_all[label[4]]Y_6= Trian_all[label[5]]Y_7= Trian_all[label[6]]Trian_all然后训练7个回归模型。
第1个模型,RMSE误差是:0.901305736956438
剩余的6个模型,复制粘贴代码,改一下标签就行。
进行预测3月1号的EERIR的百分比,结果如下
[0.46327684] [5.77683616] [22.67231638] [32.97457627] [23.68361582] [11.5819209] [2.81920904]
评价模型的好坏,除了上面的RMSE还有MAPE、MAE、MSE等误差的计算方法,都可以计算一下,做一个表格来评价模型。
改进的地方,就是可以对比其他的机器学习回归模型,比如KNN回归、随机森林回归等。
3 CodeCode获取,在浏览器中输入:betterbench.top/#/40/detail,或者Si我欢迎光临 纳金网 (http://go.narkii.com/club/) | Powered by Discuz! X2.5 |