本文整理汇总了Python中sklearn.preprocessing.StandardScaler.predict方法的典型用法代码示例。如果您正苦于以下问题:Python StandardScaler.predict方法的具体用法?Python StandardScaler.predict怎么用?Python StandardScaler.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.preprocessing.StandardScaler
的用法示例。
在下文中一共展示了StandardScaler.predict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ElasticNet
# 需要导入模块: from sklearn.preprocessing import StandardScaler [as 别名]
# 或者: from sklearn.preprocessing.StandardScaler import predict [as 别名]
fit = ElasticNet()
params = {
'l1_ratio': np.linspace(0,1,15), #15 different ratios between 0 and 1. 0 is Ridge, 1 is Lasso
'alpha': np.linspace(0,10,num=150) #150 different alpha values, alpha of 0 is non-regularized regression
}
gs = GridSearchCV(fit, param_grid=params, verbose = True, cv = 10, scoring = 'mean_absolute_error') #We apply CV 5 times
gs.fit(X_train_01, Y_train) #MAE of -1.635
gs.best_params_, gs.best_score_
##Best criteria is alpha: 0 with l1_ratio: 0, which means just regression with NO regularization
##We use these values to to test on the testing data
fit = ElasticNet(alpha=0,l1_ratio=0).fit(X_train_01, Y_train)
mean_absolute_error(Y_test, fit.predict(X_test_01)) #MAE on testing data is 1.63
###Table with the features and the coefficents
results = [list(df_raw.columns[1:-1].values.T), list(fit.coef_)]
df_results = pd.DataFrame(results).T; df_results.columns = ['Feature Name','Coefficient']
df_results
###Let us plot the true vs predicted values to visualize this result
plt.scatter(Y_test, fit.predict(X_test_01))
plt.xlabel('Actual Defensive Rating'); plt.ylabel('Predicted Defensive Rating')
###Off Rating
##Spliting the data into train and test (67% train)