当我使用管道时,我试图弄清楚如何取消缩放我的数据(大概是使用反变换)以进行预测。下面的数据只是一个例子。我的实际数据要复杂得多,但我希望使用RobustScaler(因为我的数据有异常值)和Lasso(因为我的数据有许多无用的特性)。一般来说,我对管道还不熟悉。你知道吗
基本上,如果我试图用这个模型来预测任何事情,我希望预测是无标度的。有管道可以吗?我怎样才能用反变换来实现这一点?你知道吗
import pandas as pd
from sklearn.linear_model import Lasso
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import RobustScaler
data = [[100, 1, 50],[500 , 3, 25],[1000 , 10, 100]]
df = pd.DataFrame(data,columns=['Cost','People', 'Supplies'])
X = df[['People', 'Supplies']]
y = df[['Cost']]
#Split
X_train,X_test,y_train,y_test = train_test_split(X,y)
#Pipeline
pipeline = Pipeline([('scale', RobustScaler()),
('alg', Lasso())])
clf = pipeline.fit(X_train,y_train)
train_score = clf.score(X_train,y_train)
test_score = clf.score(X_test,y_test)
print ("training score:", train_score)
print ("test score:", test_score)
#Predict example
example = [[10,100]]
clf.predict(example)
目前没有回答
相关问题 更多 >
编程相关推荐