这主要是一个git问题.我想提交我的ipython笔记本,但是要检查点.
repo有多个文件夹,每个文件夹都有ipython笔记本,因此忽略单个目录并不能解决问题.我想继续添加带有笔记本的新文件夹而不用担心它.
我的预感是必须有一种方法可以使用一些通配符来识别名为*/.ipynb_checkpoints /的文件夹中的任何内容,但是无法弄明白.
我正在运行GridSearch CV来优化scikit中分类器的参数.一旦完成,我想知道哪些参数被选为最佳参数.
每当我这样做,我得到一个AttributeError: 'RandomForestClassifier' object has no attribute 'best_estimator_',并且不知道为什么,因为它似乎是文档的合法属性.
from sklearn.grid_search import GridSearchCV
X = data[usable_columns]
y = data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
rfc = RandomForestClassifier(n_jobs=-1,max_features= 'sqrt' ,n_estimators=50, oob_score = True)
param_grid = {
'n_estimators': [200, 700],
'max_features': ['auto', 'sqrt', 'log2']
}
CV_rfc = GridSearchCV(estimator=rfc, param_grid=param_grid, cv= 5)
print '\n',CV_rfc.best_estimator_
Run Code Online (Sandbox Code Playgroud)
产量:
`AttributeError: 'GridSearchCV' object has no attribute 'best_estimator_'
Run Code Online (Sandbox Code Playgroud) TLDR:scikit的roc_curve功能仅为某个数据集返回3个点.为什么会这样,我们如何控制多少积分才能回来?
我正试图绘制一条ROC曲线,但始终得到一个"ROC三角形".
lr = LogisticRegression(multi_class = 'multinomial', solver = 'newton-cg')
y = data['target'].values
X = data[['feature']].values
model = lr.fit(X,y)
# get probabilities for clf
probas_ = model.predict_log_proba(X)
Run Code Online (Sandbox Code Playgroud)
只是为了确保长度合适:
print len(y)
print len(probas_[:, 1])
Run Code Online (Sandbox Code Playgroud)
两者都返回13759.
然后运行:
false_pos_rate, true_pos_rate, thresholds = roc_curve(y, probas_[:, 1])
print false_pos_rate
Run Code Online (Sandbox Code Playgroud)
返回[0. 0.28240129 1.]
如果我调用threasholds,我得到数组([0.4822225,-0.5177775,-0.84595197])(总是只有3分).
因此,我的ROC曲线看起来像三角形并不奇怪.
我无法理解的是为什么scikit roc_curve只返回3分.非常感谢.
我正在建立一个分类器,通过贷款俱乐部数据,并选择最好的X贷款.我训练了一个随机森林,并创建了通常的ROC曲线,混淆矩阵等.
混淆矩阵将分类器的预测(森林中树木的多数预测)作为参数.但是,我希望在不同的阈值下打印多个混淆矩阵,知道如果我选择10%最佳贷款,20%最佳贷款等会发生什么.
我从阅读其他问题中知道,改变门槛通常是一个坏主意,但有没有其他方法可以看到这些情况下的混淆矩阵?(问题A)
如果我继续更改阈值,我应该假设这样做的最佳方法是预测问题然后手动阈值,将其传递给混淆矩阵?(问题B)
classification threshold confusion-matrix random-forest scikit-learn
我有一个数据集,其中包含一些带有分类数据的列.
我一直在使用Categorical函数将数字值替换为分类值.
data[column] = pd.Categorical.from_array(data[column]).codes
Run Code Online (Sandbox Code Playgroud)
我最近碰到了pandas.get_dummies函数.这些可以互换吗?使用一个优于另一个有优势吗?
我想看看精确度和召回率如何随阈值变化(不仅仅是彼此之间)
model = RandomForestClassifier(500, n_jobs = -1);
model.fit(X_train, y_train);
probas = model.predict_proba(X_test)[:, 1]
precision, recall, thresholds = precision_recall_curve(y_test, probas)
print len(precision)
print len(thresholds)
Run Code Online (Sandbox Code Playgroud)
返回:
283
282
Run Code Online (Sandbox Code Playgroud)
因此,我不能将它们一起绘制。关于为什么会这样的任何线索?
我有一个要缩小尺寸的熊猫数据集(删除x下的所有值)。
面具是 df[my_column] > 50
我通常只使用df = df[mask],但要避免每次都进行复制,特别是因为在函数中使用它时容易出错(因为它仅在函数作用域中被更改)。
子集数据集的最佳方法是什么?
我在想一些类似的东西
df.drop(df.loc[mask].index, inplace = True)
有没有更好的方法来执行此操作,或者在任何情况下根本无法执行此操作?
我有一些数据,其中索引是一个阈值,并且值是两个类0和1的trns(真实负率).
我希望为每个类获得一个数据帧,该数据帧由tnr索引,该阈值对应于该tnr.基本上,我想要这个:
我可以通过使用以下方法实现此效果:
pd.concat([pd.Series(data[0].index.values, index=data[0]),
pd.Series(data[1].index.values, index=data[1])],
axis=1)
Run Code Online (Sandbox Code Playgroud)
或者,推广到任意数量的列:
def invert_dataframe(df):
return pd.concat([pd.Series(df[col].index.values,
index=df[col]) for col in df.columns],
axis=1)
Run Code Online (Sandbox Code Playgroud)
然而,这似乎非常hacky和容易出错.有没有更好的方法来做到这一点,是否有可能做到这一点的本机Pandas功能?
我有一个名为“分数”的系列,带有日期时间索引。
最后,我要到其子集quarter和year
伪代码:series.loc['q2 of 2013']
迄今为止的尝试:
s.dt.quarter
AttributeError:只能使用具有类似日期时间的值的 .dt 访问器
s.index.dt.quarter
AttributeError: 'DatetimeIndex' 对象没有属性 'dt'
这有效(受此答案启发),但我无法相信这是在 Pandas 中执行此操作的正确方法:
d = pd.DataFrame(s)
d['date'] = pd.to_datetime(d.index)
d.loc[(d['date'].dt.quarter == 2) & (d['date'].dt.year == 2013)]['scores']
我希望有一种方法可以做到这一点,而无需转换为数据集,将索引强制为日期时间,然后从中获取系列。
我错过了什么,在 Pandas 系列上做到这一点的优雅方式是什么?
我试图用XGBoost,优化eval_metric的auc(如描述在这里).
这在直接使用分类器时工作正常,但在我尝试将其用作管道时失败.
将.fit参数传递给sklearn管道的正确方法是什么?
例:
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
from xgboost import XGBClassifier
import xgboost
import sklearn
print('sklearn version: %s' % sklearn.__version__)
print('xgboost version: %s' % xgboost.__version__)
X, y = load_iris(return_X_y=True)
# Without using the pipeline:
xgb = XGBClassifier()
xgb.fit(X, y, eval_metric='auc') # works fine
# Making a pipeline with this classifier and a scaler:
pipe = Pipeline([('scaler', StandardScaler()), ('classifier', XGBClassifier())]) …Run Code Online (Sandbox Code Playgroud) python ×7
scikit-learn ×5
pandas ×4
commit ×1
dataframe ×1
datetime ×1
dummy-data ×1
git ×1
gitignore ×1
indexing ×1
mask ×1
masking ×1
pipeline ×1
python-2.7 ×1
reindex ×1
roc ×1
subset ×1
threshold ×1
validation ×1
xgboost ×1