小编use*_*396的帖子

如何使用对数损失指标将 sgdclassifier 铰链损失与 Gridsearchcv 结合使用?

我知道 sgdclassifier 铰链损失不支持概率估计。那么,在使用 log_loss 指标时,如何将其与 GridSearchCV 一起使用呢?

clf = SGDClassifier(loss='hinge')

grid_params = {'alpha': [0.0001, 0.001, 0.01]}
grid_search = GridSearchCV(clf, grid_params, scoring='neg_log_loss')
grid_search.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)

它返回:

AttributeError:概率估计不适用于损失='hinge'

我有什么办法可以让这项工作成功吗?

python scikit-learn grid-search

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

检查索引中是否有任何缺失日期

有没有办法直接检查数据框中的缺少日期.我想检查是否有之间缺少日期2013-01-192018-01-29

            GWA_BTC      GWA_ETH    GWA_LTC  GWA_XLM  GWA_XRP
   Date                 
2013-01-19  11,826.36   1,068.45    195.00    0.51    1.82
2013-01-20  13,062.68   1,158.71    207.58    0.52    1.75
   ...
2018-01-28  12,326.23   1,108.90    197.36    0.48    1.55
2018-01-29  11,397.52   1,038.21    184.92    0.47    1.43
Run Code Online (Sandbox Code Playgroud)

我试图手动检查,但花了很多时间.

python pandas

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

KNeighborsClassifier 欧氏距离计算

我有一个关于KNeighborsClassifier

这是我的数据集代码iris

iris = datasets.load_iris()
X = iris.data # Independent variables
y = iris.target # response or target or dependent variables

x_train, x_test, y_train,y_test = (train_test_split(X,y, test_size=0.3,
                                                   random_state=42,
                                                   stratify=y))

knn = KNeighborsClassifier(n_neighbors = 5)
knn.fit(x_train, y_train)
prediction = knn.predict(x_test)
print (accuracy_score(y_test, prediction))
Run Code Online (Sandbox Code Playgroud)

所以我知道两点之间的距离是使用欧几里德距离计算的。

例如,训练虹膜数据集有 4 个特征,测试虹膜数据集也有 4 个特征,那么如何计算这 4 列值之间的欧氏距离。假设这是我们的train数据

array([[5.1, 2.5, 3. , 1.1],
       [6.2, 2.2, 4.5, 1.5],
       [5.1, 3.8, 1.5, 0.3],
       [6.8, 3.2, 5.9, 2.3]]
Run Code Online (Sandbox Code Playgroud)

这是我们的test数据

array([[7.3, 2.9, 6.3, 1.8],
       [6.1, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning

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

tfidf 矢量化器和 tfidf 变压器有什么区别

我知道公式tfidf vectorizer

Count of word/Total count * log(Number of documents / no.of documents where word is present)
Run Code Online (Sandbox Code Playgroud)

我在 scikit learn 中看到了 tfidf 转换器,我只是想区分它们。我找不到任何有用的东西。

python nltk tf-idf scikit-learn tfidfvectorizer

2
推荐指数
3
解决办法
6138
查看次数

如何获得groupby大小的百分比

我正在寻找一种获得百分比的方法

df.groupby(['state', 'approved_or_not']).size()

Output:

school_state  project_is_approved
AK            0                         55
              1                        290
AL            0                        256
              1                       1506
AR            0                        177
              1                        872
AZ            0                        347
              1                       1800
Run Code Online (Sandbox Code Playgroud)

哪个好,但我想要的是百分比而不是计数.

school_state  project_is_approved
AK            0                        0.16
              1                        0.84
AL            0                        0.14
              1                        0.86
Run Code Online (Sandbox Code Playgroud)

我试过了,想不通办法.感谢有人可以提供帮助吗?

python pandas

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

我是否必须对训练和测试数据集分别进行一种热编码?

我正在研究分类问题,并且已经将火车数据分为火车和测试集。

我的分类列很少(大约4 -6),我正在考虑使用pd.get_dummies将分类值转换为OneHotEncoding。

我的问题是,我必须分别为训练和测试拆分做OneHotEncoding吗?如果是这种情况,我必须使用sklearn OneHotEncoder,因为它支持fit和transform方法。

python machine-learning

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

将嵌套列表中的所有元素转换为整数

我有一个整数列表作为字符串,所以如何将其转换回来

lst = ["['1','2']", "['2','4']", "['1','4']", "['1','5']", "['3','5']", "['3','4']"]
Run Code Online (Sandbox Code Playgroud)

我试图使用列表理解

[j for j in i if j.isdigit() for i in lst ]
Run Code Online (Sandbox Code Playgroud)

但它回来了

['3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4']
Run Code Online (Sandbox Code Playgroud)

期望的输出:

[[1,2],[2,4],[1,4],[1,5],[3,5],[3,4]]
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

python python-3.x

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