小编ldi*_*rer的帖子

在 scikit-learn 中结合递归特征消除和网格搜索

我试图在 scikit-learn 中结合递归特征消除和网格搜索。正如您从下面的代码(有效)中看到的那样,我能够从网格搜索中获得最佳估计量,然后将该估计量传递给 RFECV。但是,我宁愿先进行 RFECV,然后再进行网格搜索。问题是,当我将选择器 ?from RFECV 传递给网格搜索时,它不接受:

ValueError:估计器 RFECV 的参数引导程序无效

是否可以从 RFECV 获取选择器并将其直接传递给 RandomizedSearchCV,或者这在程序上不是正确的做法?

from sklearn.datasets import make_classification
from sklearn.feature_selection import RFECV
from sklearn.grid_search import GridSearchCV, RandomizedSearchCV
from sklearn.ensemble import RandomForestClassifier
from scipy.stats import randint as sp_randint

# Build a classification task using 3 informative features
X, y = make_classification(n_samples=1000, n_features=25, n_informative=5, n_redundant=2, n_repeated=0, n_classes=8, n_clusters_per_class=1, random_state=0)

grid = {"max_depth": [3, None],
        "min_samples_split": sp_randint(1, 11),
        "min_samples_leaf": sp_randint(1, 11),
        "bootstrap": [True, False],
        "criterion": ["gini", "entropy"]}

estimator = RandomForestClassifierCoef()
clf = …
Run Code Online (Sandbox Code Playgroud)

feature-selection scikit-learn grid-search

7
推荐指数
1
解决办法
2821
查看次数

为什么storybook/react中需要ComponentStory、ComponentMeta

import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import Button, { Props } from 'components/Button';

export default {
  title: 'UI/Button',
  component: Button,
  argTypes: {},
} as ComponentMeta<typeof Button>;

const Template: ComponentStory<typeof Button> = ({
  onClick,
  children,
}: Props) => <Button onClick={onClick}>{children}</Button>;

export const Primary = Template.bind({});

Primary.args = {
  children: 'Button',
};

Run Code Online (Sandbox Code Playgroud)

我真的不明白ComponentMeta<typeof Button>真正添加的是什么,而且ComponentStory<typeof Button>,当您不添加它时,typescript只是突出显示.args上不存在的内容Template。而且,typeof Button它只是一个function. 它可以写得更好或更简单,还是我可以跳过它,它看起来很奇怪,就像样板文件一样?

reactjs storybook

7
推荐指数
1
解决办法
2765
查看次数

使用`__slots__`的动机是什么?

使用Sanic(Python中的异步Web框架),我试图将自定义数据添加到请求中:

request.user = 'A nice user'
Run Code Online (Sandbox Code Playgroud)

但我不能,request是类型Request,不允许这样.

查看Request该类的源代码:

class Request(dict):
    """Properties of an HTTP request such as URL, headers, etc."""
    __slots__ = (
        'app', 'headers', 'version', 'method', '_cookies', 'transport',
        'body', 'parsed_json', 'parsed_args', 'parsed_form', 'parsed_files',
        '_ip', '_parsed_url', 'uri_template', 'stream', '_remote_addr',
        '_socket', '_port', '__weakref__'
    )
Run Code Online (Sandbox Code Playgroud)

在查找互联网时,dict通过拉取请求添加了此继承,以允许将数据附加到Request对象.

所以推荐的方法是:

request['user'] = 'A nice user'
Run Code Online (Sandbox Code Playgroud)

这一切都很好,我理解它是如何工作的.

但是,我__slots__对此类的使用感到困惑,因为它继承自dict.

允许将数据附加到此类实例的另一种方法是__slots__完全删除(然后我们可以完成request.user = ...). …

python slots

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

class_weight在linearSVC和LogisticRegression的损失函数中的作用

我想弄清楚到底损失函数公式是什么,以及如何我可以手动时计算它class_weight='auto'的情况下svm.svc,svm.linearSVC和linear_model.LogisticRegression。

要获得平衡的数据,请说您拥有训练有素的分类器:clf_c。后勤损失应为(我正确吗?):

def logistic_loss(x,y,w,b,b0):
    '''
    x: nxp data matrix where n is number of data points and p is number of features.
    y: nx1 vector of true labels (-1 or 1).
    w: nx1 vector of weights (vector of 1./n for balanced data).
    b: px1 vector of feature weights.
    b0: intercept.
    '''
    s = y
    if 0 in np.unique(y):
        print 'yes'
        s = 2. * y - 1
    l = np.dot(w, …
Run Code Online (Sandbox Code Playgroud)

svm scikit-learn logistic-regression

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

排序功能似乎没有打破关系

我刚开始学习Haskell.我正在经历"真实世界Haskell"的练习,第3章,我对我不理解的行为感到难过.

我不明白为什么我grahamSort似乎没有正确地打破关系.该函数首先找到一个参考点P(直通grahamGetFirstCandidate),然后根据它们和P形成的角度对其他点进行排序.我使用(减去)余弦作为角度的代理.
grahamGetFirstCandidate似乎按预期工作.

代码(对不起,它可能不是很干净):

import Data.List as List

data TwoD = TwoD {
x :: Float,
y :: Float
} deriving (Show, Eq)

dotProduct :: TwoD -> TwoD -> Float
dotProduct (TwoD xa ya) (TwoD xb yb) = xa * xb + ya * yb

grahamGetFirstCandidate :: [TwoD] -> TwoD
grahamGetFirstCandidate [] = error "Trying to find point with minimum y in empty List"
grahamGetFirstCandidate (p:ps) = search p ps where
    search :: TwoD -> …
Run Code Online (Sandbox Code Playgroud)

haskell

2
推荐指数
1
解决办法
89
查看次数