本文整理匯總了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)