管道拟合只接受2个参数

2024-04-19 21:58:56 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码。在

import pandas as pd 
import numpy as np
import json
import seaborn as sb 
from sklearn.metrics import log_loss
from sklearn import linear_model 
from sklearn.model_selection import StratifiedKFold
from sklearn.svm import SVC
from scipy.stats import zscore
from Transformers import TextTransformer
from sklearn.metrics import confusion_matrix, accuracy_score
from sklearn.model_selection import GridSearchCV
%matplotlib inline
df = pd.read_json('data/train.json', encoding = 'utf-8', dtype = {'description': str})
from sklearn.pipeline import Pipeline, FeatureUnion
a = TextTransformer('description', max_features=50)
b = TextTransformer('features', max_features=10)
pipeline = Pipeline([
    ('feats', FeatureUnion([
        ('description',a ), # can pass in either a pipeline
        ('features',b ) # or a transformer
    ])),
    ('clf', SVC())  # classifier
])
pipeline.fit(df)

我好奇的是,我试图预测一个目标变量df['interest_level']。然而,管道.fit只接受2个参数,其中一个是self。那么如何传入目标变量呢?在

另一点要注意的是我试过了管道.fit(df,y=df['interest_level']),它也会引发相同的异常。我正在使用pandas/numpy/sklearn的最新版本。在

^{pr2}$

Tags: fromimportnumpyjsonpandasdfmodelpipeline