python gridsearch_python gridsearch中的内存错误

博客讲述使用Python的网格搜索模块对有20000列和110000行的数据帧进行参数调整,构建了包含TfidfVectorizer和LinearSVC的管道,并设置了参数范围。但在运行时出现MemoryError错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我需要应用网格搜索我有20000列和110000行的数据帧,我需要使用python的网格搜索模块调整我的参数

#validation for svm

#there are an error to check it ( grid search ne marche pas i will check why after)

label = df.Sentiment

train= df.drop('Sentiment', axis=1)

from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),

('clf', LinearSVC()),

])

from sklearn.model_selection import GridSearchCV

parameters = {'tfidf_min_df': [[0.8, 1.0], 1],

'tfidf__max_df': ([0.8, 1.0], 1),

'clf__c': (0.1, 1 , 10),

}

gs_clf = GridSearchCV(text_clf, parameters)

gs_clf = gs_clf.fit(trainas_matrix(), label)

我得到这个错误

------------------------------------------------- -------------------------- MemoryError Traceback(最近一次调用last)in()3 classif = SklearnClassifier(LinearSVC())4#Séparationdu set de train et de test ----> 5 X_train,X_test,y_train,y_test = train_test_split(train.as_matrix(),label,test_size = 0.33)/usr/local/lib/python2.7/dist-packages/pandas as_matrix中的/ core/generic.pyc(self,columns)2832 self._consolidate_inplace()2833 if self._AXIS_REVERSED: - > 2834 return self._data.as_matrix(columns).T 2835 return self._data.as_matrix(columns)2836 as_matrix中的/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc(self,items)3148返回mgr.blocks [0] .get_values()3149其他: - > 3150返回mgr . _interleave()3151 3152 def _interleave(self):/ interleave中的/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc(self)3157 dtype = _interleaved_dtype(self.blocks)3158 - > 3159 result = np.empty(self.shape,dtype = dtype)3160 3161 if result.shape [0] == 0:MemoryEr ROR:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值