我正在尝试使用一系列样本权重来运行简单的Sklearn Ridge回归.X_train是一个~200k×100的2D Numpy阵列.我尝试使用sample_weight选项时出现内存错误.没有这个选项,它工作得很好.为了简单起见,我将功能减少到2,而sklearn仍然会让我感到内存错误.有任何想法吗?
model=linear_model.Ridge()
model.fit(X_train, y_train,sample_weight=w_tr)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/linear_model/ridge.py", line 449, in fit
return super(Ridge, self).fit(X, y, sample_weight=sample_weight)
File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/linear_model/ridge.py", line 338, in fit
solver=self.solver)
File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/linear_model/ridge.py", line 286, in ridge_regression
K = safe_sparse_dot(X, X.T, dense_output=True)
File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/utils/extmath.py", line 83, in safe_sparse_dot
return np.dot(a, b)
MemoryError
Run Code Online (Sandbox Code Playgroud) 我想将 sklearn 的 CalibratedClassifierCV 与 sklearn 的 SVC 结合使用来对多类(9 类)预测问题进行预测。但是,当我运行它时,出现以下错误。相同的代码在不同的模型(即 RandomForestCalssifier)下运行没有问题。
kf = StratifiedShuffleSplit(y, n_iter=1, test_size=0.2)
clf = svm.SVC(C=1,probability=True)
sig_clf = CalibratedClassifierCV(clf, method="isotonic", cv=kf)
sig_clf.fit(X, y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/calibration.py", line 166, in fit
calibrated_classifier.fit(X[test], y[test])
File "/home/g/anaconda/lib/python2.7/site-packages/sklearn/calibration.py", line 309, in fit
calibrator.fit(this_df, Y[:, k], sample_weight)
IndexError: index 9 is out of bounds for axis 1 with size 9
Run Code Online (Sandbox Code Playgroud) 我知道如何在其基本公式中使用累积和,代码如下:
Table Name: Employees
dept_id salary
-------------
10 1000
10 1000
10 2000
10 3000
20 5000
20 6000
20 NULL
SELECT dept_id,
salary,
SUM(salary) OVER(PARTITION BY dept_id
ORDER BY salary ASC
rows unbounded preceding) cum_sum
FROM Employees;
dept_id salary cum_sum
--------------------------
10 1000 1000
10 1000 2000
10 2000 4000
10 3000 7000
20 5000 5000
20 6000 11000
20 NULL 11000
Run Code Online (Sandbox Code Playgroud)
但是,如何将累积总和限制为仅前N行?例如,将累积和限制为当前行和前两行.
dept_id salary cum_sum
--------------------------
10 1000 1000
10 1000 2000
10 2000 4000
10 3000 6000 …Run Code Online (Sandbox Code Playgroud) 如何返回 CatBoost 模型的所有超参数?
注意:我不认为这是Print CatBoost 超参数的重复,因为该问题/答案不能满足我的需要。
例如,使用 sklearn 我可以做到:
rf = ensemble.RandomForestClassifier(min_samples_split=2)
print rf
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
max_depth=None, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
oob_score=False, random_state=None, verbose=0,
warm_start=False)
Run Code Online (Sandbox Code Playgroud)
这将返回所有超参数,我定义的参数和其他默认值。
使用 Catboost 我可以使用 .get_params() 但它似乎只返回用户指定的参数:
cat = CatBoostClassifier(loss_function='Logloss',
verbose = False,
eval_metric='AUC',
iterations=500,
thread_count = None,
random_state=SEED)
print cat.get_params()
{'iterations': 500, 'random_state': 42, 'verbose': False, 'eval_metric': 'AUC', 'loss_function': 'Logloss'}
Run Code Online (Sandbox Code Playgroud)
例如,我想知道使用了什么 learning_rate,但理想情况下可以获取整个列表。
我正在从csv文件导入一些数据.该文件的nan值标记为文本"NA".我导入数据:
X = genfromtxt(data, delimiter=',', dtype=float, skip_header=1)
Run Code Online (Sandbox Code Playgroud)
我使用此代码用一个普遍计算的列平均值替换nan.
inds = np.where(np.isnan(X))
X[inds]=np.take(col_mean,inds[1])
Run Code Online (Sandbox Code Playgroud)
然后我运行几个检查并获得空数组:
np.where(np.isnan(X))
np.where(np.isinf(X))
Run Code Online (Sandbox Code Playgroud)
最后我运行了一个scikit分类器:
RF = ensemble.RandomForestClassifier(n_estimators=100,n_jobs=-1,verbose=2)
RF.fit(X, y)
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
File "C:\Users\m&g\Anaconda\lib\site-packages\sklearn\ensemble\forest.py", line 257, in fit
check_ccontiguous=True)
File "C:\Users\m&g\Anaconda\lib\site-packages\sklearn\utils\validation.py", line 233, in check_arrays
_assert_all_finite(array)
File "C:\Users\m&g\Anaconda\lib\site-packages\sklearn\utils\validation.py", line 27, in _assert_all_finite
raise ValueError("Array contains NaN or infinity.")
ValueError: Array contains NaN or infinity.
Run Code Online (Sandbox Code Playgroud)
有什么想法告诉我有NaN或无穷大?我看过这篇文章并尝试运行:
RF.fit(X.astype(float), y.astype(float))
Run Code Online (Sandbox Code Playgroud)
但我得到了同样的错误.
我有一个具有简单xml结构的文件,希望将其加载到Postgres表中。
<rows>
<field name="id">1</field>
<field name="age">75-84</field>
<field name="gndr">F</field>
<field name="inc">32000-47999</field>
</rows>
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法吗?
python ×4
scikit-learn ×3
anaconda ×1
catboost ×1
github ×1
install ×1
load ×1
nan ×1
netezza ×1
package ×1
parsing ×1
postgresql ×1
python-2.7 ×1
regression ×1
sql ×1
svm ×1
xml ×1