小编sto*_*ock的帖子

如何调整相关图的大小以获得更好的可视化?

我有包含 72 个特征的数据集。现在我想找到会影响我的模型的最重要的特征。因此,我尝试使用seaborn和绘制相关矩阵图,matplotlib但是当我尝试绘制它时,因为它包含 72 个特征,因此无法正确地将其可视化。我怎样才能放大情节以更好地理解它。

代码:

%matplotlib inline
corr = data.corr()
sns.heatmap(corr, 
            xticklabels=corr.columns.values,
            yticklabels=corr.columns.values)
Run Code Online (Sandbox Code Playgroud)

截屏:

在此处输入图片说明

python data-visualization pandas seaborn

6
推荐指数
0
解决办法
2316
查看次数

如何在SelectFromModel()中确定用于选择特征的阈值?

我正在使用随机森林分类器进行特征选择。我总共拥有70个功能,并且我要从70个功能中选择最重要的功能。下面的代码显示了分类器,该分类器显示了从最高有效到最低有效的功能。

码:

feat_labels = data.columns[1:]
clf = RandomForestClassifier(n_estimators=100, random_state=0)

# Train the classifier
clf.fit(X_train, y_train)

importances = clf.feature_importances_
indices = np.argsort(importances)[::-1]

for f in range(X_train.shape[1]):
    print("%2d) %-*s %f" % (f + 1, 30, feat_labels[indices[f]], importances[indices[f]]))  
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

现在,我尝试使用SelectFromModelfrom,sklearn.feature_selection但是如何确定给定数据集的阈值。

# Create a selector object that will use the random forest classifier to identify
# features that have an importance of more than 0.15
sfm = SelectFromModel(clf, threshold=0.15)

# Train the selector
sfm.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)

当我尝试threshold=0.15然后尝试训练我的模型时,出现错误,提示数据太嘈杂或选择太严格。

但是,如果我使用该threshold=0.015模型,就能够在选定的新功能上训练我的模型,那么如何确定该阈值?

python numpy machine-learning pandas scikit-learn

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

ValueError:使用 sklearn roc_auc_score 函数不支持多类多输出格式

logistic regression用于预测。我的预测是0's1's。在给定数据上训练我的模型之后,以及在训练重要特征时,即X_important_train看到截图。我得到大约 70% 的分数但是当我使用roc_auc_score(X,y)roc_auc_score(X_important_train, y_train)我得到值错误时: ValueError: multiclass-multioutput format is not supported

代码:

# Load libraries
from sklearn.linear_model import LogisticRegression
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import roc_auc_score

# Standarize features
scaler = StandardScaler()
X_std = scaler.fit_transform(X)

# Train the model using the training sets and check score
model.fit(X, y)
model.score(X, y)

model.fit(X_important_train, y_train)
model.score(X_important_train, y_train)

roc_auc_score(X_important_train, y_train)
Run Code Online (Sandbox Code Playgroud)

截屏:

在此处输入图片说明

python pandas scikit-learn logistic-regression

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

如何在 Reactjs 组件中使用普通 JavaScript?

我正在使用chartist.js,并且我正在reactjs组件中使用chartist。我指的是这个http://gionkunz.github.io/chartist-js/examples.html#simple-pie-chart

图表师.js:

var Chartist = {
    version:'0.9.5' 
}

(function (window, document, Chartist) {

var options = {
  labelInterpolationFnc: function(value) {
    return value[0]
  }
};

var responsiveOptions = [
  ['screen and (min-width: 640px)', {
    chartPadding: 30,
    labelOffset: 100,
    labelDirection: 'explode',
    labelInterpolationFnc: function(value) {
      return value;
    }
  }],
  ['screen and (min-width: 1024px)', {
    labelOffset: 80,
    chartPadding: 20
  }]
];

})();
Run Code Online (Sandbox Code Playgroud)

Reactjs组件:

import React, { Component } from 'react';

var data = {
  labels: ['Bananas', 'Apples', 'Grapes'],
  series: [20, 15, 40]
}; …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

如何根据其他列的值估算NaN值?

我在数据框中有2列

1)工作经验(年)

2)company_type

我想根据工作经验列来估算company_type列。company_type列具有要根据工作经验列填写的NaN值。工作经验列没有任何缺失值。

这里work_exp是数字数据,company_type是类别数据。

示例数据:

Work_exp      company_type
   10            PvtLtd
   0.5           startup
   6           Public Sector
   8               NaN
   1             startup
   9              PvtLtd
   4               NaN
   3           Public Sector
   2             startup
   0               NaN 
Run Code Online (Sandbox Code Playgroud)

我已经决定了估算NaN值的阈值。

Startup if work_exp < 2yrs
Public sector if work_exp > 2yrs and <8yrs
PvtLtd if work_exp >8yrs
Run Code Online (Sandbox Code Playgroud)

基于上述阈值标准,我该如何在company_type列中估算缺少的分类值。

python pandas

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

如何在python中找到对称均值绝对误差?

如何使用numpy或pandas计算python中的对称平均绝对误差?scikit sklearn中是否存在度量标准?

示例数据:

Actual value:   2,3,4,5,6,7,8,9
Forecast value: 1,3,5,4,6,7,10,7
Run Code Online (Sandbox Code Playgroud)

SMAPE的公式见下面的截图:

在此输入图像描述

如何使用pandas或numpy在python中完成它并计算SMAPE.

注意:有关SMAPE的更多信息:https://en.wikipedia.org/wiki/Symmetric_mean_absolute_percentage_error

python statistics numpy pandas scikit-learn

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

如何在 Reactjs 中按升序或降序对数据进行排序?

我有要导入到我的显示组件中的产品数据。对于我.map()用来显示内容的JSON 中的每个产品。现在我想按升序或降序对产品价格进行排序,但我无法做到。

产品.js:

 const products = [
  {
    "index": 0,
    "isSale": true,
    "isExclusive": false,
    "price": "Rs.2000",
    "productImage": "product-1.jpg",
    "productName": "Striped shirt",
    "size": ["XS", "S", "L", "XL"]
  },
  {
    "index": 1,
    "isSale": false,
    "isExclusive": false,
    "price": "Rs.1250",
    "productImage": "product-2.jpg",
    "productName": "Denim shirt",
    "size": ["XS", "S"]
  },
  {
    "index": 2,
    "isSale": false,
    "isExclusive": true,
    "price": "Rs.1299",
    "productImage": "product-3.jpg",
    "productName": "Plain cotton t-shirt",
    "size": ["S", "M"]
  },
  {
    "index": 3,
    "isSale": false,
    "isExclusive": false,
    "price": "Rs.1299",
    "productImage": "product-4.jpg",
    "productName": "Plain 3/4 …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

如何在Reactjs中删除元素onclick?

我制作了CARD的显示器username.当我点击删除按钮即交叉或取消按钮时,它应该从tasklist这里的任务列表状态变量中删除CARD .我正在使用.map()方法迭代每个任务并显示它.我想删除特定用户的任务卡,当我点击红色十字按钮(见截图)时,目前只有窗口出现说 - > are you sure you want to delete it如果我点击是,它应该删除它.

码:

import React, {Component} from "react"; 

export default class Tasks extends Component{
    constructor(props){
        super(props);
        this.state = {
            taskList:[],
            taskName:"",
            type:"classification",
            datasetName:"",
            allDatasets:[],
            users:[],
            names:[]
        }
    }

triggerDelete(task){
        if(window.confirm("Are you sure you want to delete this task?")){

        }
    }

render(){
        return(
            <div className="tasks-wrap">
                <h1 onClick={()=>{
                   this.props.history.push("/taskdetails");
                }}>Your Tasks</h1>
                {
                            this.state.taskList.map((task,index)=>{
                                return(
                                    <div key={index} className="item-card" onClick={()=>{
                                        window.sessionStorage.setItem("task",JSON.stringify(task));
                                        this.props.history.push("/taskdetails/");
                                    }}>
                                        <div className="name">{task.name}</div>
                                        <div className="sub"> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

如何在 Chartist.js 中使用插件?

我正在使用 Chartist.js 制作饼图组件。我想使用图例插件https://codeyellowbv.github.io/chartist-plugin-legend/

我的饼图中没有得到图例。请参阅下面的屏幕截图

代码:

import React, { Component } from 'react';
import ChartistGraph from "react-chartist";
import Legend from "chartist-plugin-legend";

import './piechart.css';

let options = {
  width:400,
  height:500,
  labelInterpolationFnc: function(value) {
    return value[0]
  }
};


let plugin = {
    plugin:'legend'
}


class Chart extends Component {

  render(){
    return(
      <div>
          <div className="center">
          <ChartistGraph data={data} options={options} plugins={plugin} type="Pie"/>
          </div>
      </div>

    )}

}

export default Chart;
Run Code Online (Sandbox Code Playgroud)

截屏:

在此输入图像描述

reactjs chartist.js

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

反应本机中未处理的承诺拒绝错误?

我正在使用axios从API端点获取数据。我收到错误->可能未处理的承诺拒绝类型错误:undefined不是一个函数(评估res.json())

我在React Native应用中使用react-redux和redux-thunk。

placeAction.js:

import { FETCH_VENUES } from './types';
import axios from 'axios';

export const fetchVenues = () => dispatch => {
    axios.get(`my_api_link`)
    .then( res => res.json())
    .then( venues => 
        dispatch({
            type: FETCH_VENUES,
            payload: venues
        })
    )
    .catch( error => {
        console.log(error);
    });
};
Run Code Online (Sandbox Code Playgroud)

检查以下屏幕截图:

在此处输入图片说明

javascript reactjs react-native axios

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