小编gow*_*oww的帖子

roc_auc_score()和auc()的结果不同

我无法理解scikit-learn 之间roc_auc_score()和之间的区别(如果有的话)auc().

我想用不平衡的类来预测二进制输出(Y = 1时约为1.5%).

分类

model_logit = LogisticRegression(class_weight='auto')
model_logit.fit(X_train_ridge, Y_train)
Run Code Online (Sandbox Code Playgroud)

罗克曲线

false_positive_rate, true_positive_rate, thresholds = roc_curve(Y_test, clf.predict_proba(xtest)[:,1])
Run Code Online (Sandbox Code Playgroud)

AUC的

auc(false_positive_rate, true_positive_rate)
Out[490]: 0.82338034042531527
Run Code Online (Sandbox Code Playgroud)

roc_auc_score(Y_test, clf.predict(xtest))
Out[493]: 0.75944737191205602
Run Code Online (Sandbox Code Playgroud)

有人可以解释这个区别吗?我以为两者都只计算ROC曲线下的面积.可能是因为数据集不平衡但我无法弄清楚原因.

谢谢!

python machine-learning scikit-learn

35
推荐指数
3
解决办法
4万
查看次数

基于AUC的功能使用随机森林的重要性

我试图用随机森林和逻辑回归预测二元变量.我有很多不平衡的课程(约占Y = 1的1.5%).

随机森林中的默认特征重要性技术基于分类准确性(错误率) - 已被证明是不平衡类的不良衡量标准(参见此处此处).

用于RF特性选择的两个标准VIM是Gini VIM和置换VIM.粗略地说,一个感兴趣的预测器的基尼VIM是森林中由该预测器产生的基尼杂质减少的总和,无论何时选择用于分裂,通过树的数量来缩放.

我的问题是:在scikit-learn中实现的那种方法(就像在R包中一样party)?或者可能是一种解决方法?

PS:这个问题与其他问题有关.

python scoring machine-learning scikit-learn

6
推荐指数
1
解决办法
2480
查看次数

多个子图的GridSpec"正在清除包含传递轴的图形"

df.hist(columns=, by=)想在GridSpec(2,2)中插入4种不同的东西.

他们每个人都是这样的:

在此输入图像描述

这是代码:

stuff = [df1, df2, df4, df3]
col = ['blue', 'orange', 'grey', 'green']
fig = plt.figure(figsize=(10,10))
gs = gridspec.GridSpec(2, 2)

for i in range(0, len(stuff)):
    ax = plt.subplot(gs[i])
    stuff[i].hist(column='quanti_var', by=stuff[i].quali_var, alpha=.5, color=col[i], ax=ax)
Run Code Online (Sandbox Code Playgroud)

我有以下用户警告:

C:\Anaconda3\lib\site-packages\pandas\tools\plotting.py:3234: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
  "is being cleared", UserWarning)
Run Code Online (Sandbox Code Playgroud)

而不是我要找的输出:

在此输入图像描述

我尝试了几件事,包括使用SubplotSpec没有成功.任何的想法 ?

谢谢你们把你的神经元借给我!

python matplotlib histogram pandas subplot

5
推荐指数
1
解决办法
1487
查看次数

Folium Choropleth + GeoJSON引发AttributeError:'NoneType'

我正在尝试使用大草做一个choropleth ,它在GeoJSON,Pandas和传单之间提供了一个很好的链接。

GeoJSON格式如下:

{
  "type":"FeatureCollection",
  "features":[
        {
          "type":"Feature",
          "geometry":
          {
              "type":"Polygon",
              "coordinates":[[[-1.6704591323124895,49.62681486270549], .....
              {
                  "insee":"50173",
                  "nom":"Équeurdreville-Hainneville",
                  "wikipedia":"fr:Équeurdreville-Hainneville",
                  "surf_m2":12940306}},
Run Code Online (Sandbox Code Playgroud)

熊猫DataFrame:

postal_count.head(5)
Out[98]: 
  Code_commune_INSEE  CP_count
0              75120       723
1              75115       698
2              75112       671
3              75118       627
4              75111       622
Run Code Online (Sandbox Code Playgroud)

“ Code_communes_INSEE”对应于GeoJSON中的属性“ insee”。我想在上面的DataFrame中使用变量“ CP_count”来做一个choropleth。

这是我的代码(此笔记本的摘录)

map_france = folium.Map(location=[47.000000, 2.000000], zoom_start=6)
map_france.choropleth(
                    geo_str=open(geo_path + 'simplified_communes100m.json').read(),
                    data=postal_count,
                    columns=['Code_commune_INSEE', 'CP_count'],
                    key_on='feature.geometry.properties.insee',
                    fill_color='YlGn',
)
map_france.save(table_path + 'choro_test1.html')
Run Code Online (Sandbox Code Playgroud)

我仍然一次又一次收到此错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-83-ea0fd2c1c207> in <module>()
      8                     fill_color='YlGn',
      9 ) …
Run Code Online (Sandbox Code Playgroud)

geojson pandas leaflet choropleth folium

5
推荐指数
1
解决办法
1548
查看次数

注释seaborn Factorplot

我想在一个seaborn FactorPlot中可视化存储为列的2个布尔信息.

这是我的df:

在此输入图像描述

我想的都可视化actual_group,并adviced_group在同一FactorPlot.

现在我只能adviced_groups使用hue参数绘图:

在此输入图像描述

使用以下代码:

 _ = sns.factorplot(x='groups',
                    y='nb_opportunities',
                    hue='adviced_groups',
                    size=6,
                    kind='bar',
                    data=df)
Run Code Online (Sandbox Code Playgroud)

我尝试使用ax.annotate()from matplotlib但没有任何成功,因为 - 据我所知 - Axes不是由sns.FactorPlot()方法处理的.

它可以是一个注释,为矩形的一个边缘着色或任何可以帮助可视化实际组的东西.

结果可能是这样的事情:

在此输入图像描述

python matplotlib pandas seaborn

3
推荐指数
1
解决办法
6006
查看次数

单击打开 PDF - 您可能需要适当的加载程序来处理此文件类型

我正在尝试将 PDF 导入到 .js 文件中,以便将其Click to open pdf放入我的渲染中。

输入

import myFile from './assets/files/myfile.pdf';
Run Code Online (Sandbox Code Playgroud)

渲染

  render() {
return (
      ...
            <a href={myFile}>
              <span>Click to open PDF</span>
            </a>
      ...
)}
Run Code Online (Sandbox Code Playgroud)

错误

myProject.bundle.js:88481 ./assets/files/myfile.pdf 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
Run Code Online (Sandbox Code Playgroud)

Webpack.config.js

我尝试了几个 PDF 加载器但没有成功,下面的 webpack 使用url-loader.

const path = require('path'),
      webpack = require('webpack'),
      CleanWebpackPlugin = require('clean-webpack-plugin'),
      HtmlWebpackPlugin = require('html-webpack-plugin'),
      ExtractTextPlugin …
Run Code Online (Sandbox Code Playgroud)

html javascript pdf reactjs webpack

3
推荐指数
1
解决办法
7776
查看次数