Python 3.x 这是使用pd.get_假人的正确方法吗?
我有一个数据框架,它既有分类变量也有数字变量。在我的回归模型中,我想同时使用分类数据和数值数据Python 3.x 这是使用pd.get_假人的正确方法吗?,python-3.x,machine-learning,Python 3.x,Machine Learning,我有一个数据框架,它既有分类变量也有数字变量。在我的回归模型中,我想同时使用分类数据和数值数据 df_w_dummies = pd.get_dummies(df, columns =['Publisher','Platform','Genre','Publisher_Country','Publisher_Continent'], drop_first = True) features_dummies = df_w_dummies.loc[
df_w_dummies = pd.get_dummies(df, columns =['Publisher','Platform','Genre','Publisher_Country','Publisher_Continent'],
drop_first = True)
features_dummies = df_w_dummies.loc[:, df_w_dummies.columns != 'NA_Sales']
target_dummies = df_w_dummies.loc[:,'NA_Sales'].dropna()
我还试图通过添加'drop_first'关键字作为True来避免多重共线性
如有任何建议/意见,将不胜感激
这不是很漂亮。。。但下面是一些数据的示例
Name Platform Publisher Chartz_Score User_Score Critic_Score Global_Sales NA_Sales EU_Sales JP_Sales Other_Sales Year_of_Release Genre Year Total_Tweets Publisher_Country Publisher_Continent Publisher_Lat Publisher_Long
Super Mario Bros. Nintendo Nintendo EAD NaN 10.0 NaN 60.312336 89.184016 16.740672 53.505894 0.77 1985-10-18 Platform 1985.0 NaN MX North America 14.88102 -92.27582
Wii Sports Resort Nintendo Nintendo EAD 8.8 8.0 8.8 49.311030 47.873538 51.344296 25.849397 3.02 2009-07-26 Sports 2009.0 296.0 GB Europe 14.88102 -92.27582
它看起来不错,除非在目标变量中添加.dropna(),它可能/可能与功能变量的大小不同。因此,如果要在数据中删除NaN值,应该在开始时执行
df = df.dropna(subset=['NA_Sales'])
向我们展示df的样本数据。谢谢