小编gab*_*how的帖子

在sklearn中StratifiedKFold和StratifiedShuffleSplit之间的区别

从标题我想知道它们之间有什么区别

StratifiedKFold,参数shuffle = True

StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
Run Code Online (Sandbox Code Playgroud)

StratifiedShuffleSplit

StratifiedShuffleSplit(n_splits=10, test_size=’default’, train_size=None, random_state=0)
Run Code Online (Sandbox Code Playgroud)

使用StratifiedShuffleSplit有什么好处

python scikit-learn cross-validation

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

git clone ssh权限被拒绝

我按照https://help.github.com/articles/generating-ssh-keys上的说明进行操作 并输入

ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

我收到了消息

Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
Run Code Online (Sandbox Code Playgroud)

当我尝试使用ssh克隆存储库时

git clone ssh://github.com/username/repository.git
Run Code Online (Sandbox Code Playgroud)

我明白了

Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

如果我输入

ssh-add -l
Run Code Online (Sandbox Code Playgroud)

我看到3个键附有我的电子邮件地址(k1)和其他2个内部~/.ssh/id_rsa (RSA)(k2和k3).键k3与k1相同

如果我打字

ssh -vT git@github.com
Run Code Online (Sandbox Code Playgroud)

一切都很好......唯一让我思考的是

debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.0
Run Code Online (Sandbox Code Playgroud)

git ssh

12
推荐指数
4
解决办法
7万
查看次数

使用 get_dummies 时删除冗余列

嗨,有一个df包含分类变量的熊猫数据框。

df=pandas.DataFrame(data=[['male','blue'],['female','brown'],
['male','black']],columns=['gender','eyes'])

df
Out[16]: 
   gender   eyes
0    male   blue
1  female  brown
2    male  black
Run Code Online (Sandbox Code Playgroud)

使用函数 get_dummies 我得到以下数据帧

df_dummies = pandas.get_dummies(df)

df_dummies
Out[18]: 
   gender_female  gender_male  eyes_black  eyes_blue  eyes_brown
0              0            1           0          1           0
1              1            0           0          0           1
2              0            1           1          0           0
Run Code Online (Sandbox Code Playgroud)

Owever 列gender_femalegender_male包含相同的信息,因为原始列可以采用二进制值。有没有(智能)方法只保留两列中的一列?

更新

指某东西的用途

df_dummies = pandas.get_dummies(df,drop_first=True)
Run Code Online (Sandbox Code Playgroud)

会给我

df_dummies
Out[21]: 
   gender_male  eyes_blue  eyes_brown
0            1          1           0
1            0          0           1
2            1          0           0
Run Code Online (Sandbox Code Playgroud)

但我想删除最初只有两种可能性的列

想要的结果应该是 …

python pandas categorical-data

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

在pandas数据帧中查找连接inf的单元格的行位置和列名称

如何在多列熊猫数据帧中检索包含inf的列名和所有单元格的行df

我试过了

inds = np.where(np.isinf(df)==True)
Run Code Online (Sandbox Code Playgroud)

但我没有预期的结果

python dataframe pandas

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

在熊猫数据框中查找重复的行

我试图在熊猫数据框中找到重复的行。

df=pd.DataFrame(data=[[1,2],[3,4],[1,2],[1,4],[1,2]],columns=['col1','col2'])

df
Out[15]: 
   col1  col2
0     1     2
1     3     4
2     1     2
3     1     4
4     1     2

duplicate_bool = df.duplicated(subset=['col1','col2'], keep='first')
duplicate = df.loc[duplicate_bool == True]

duplicate
Out[16]: 
   col1  col2
2     1     2
4     1     2
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以添加引用第一个重复项的索引的列(保留一个)

duplicate
Out[16]: 
   col1  col2  index_original
2     1     2               0
4     1     2               0
Run Code Online (Sandbox Code Playgroud)

注意:在我的情况下,df可能非常大。

python duplicates dataframe pandas

7
推荐指数
2
解决办法
9148
查看次数

无法使用scipy读取MAT文件

我正在尝试使用scipy读取matlab文件

import scipy.io as sio

data = sio.loadmat(filepath)
Run Code Online (Sandbox Code Playgroud)

但我得到了错误

ValueError: Did not fully consume compressed contents of an miCOMPRESSED element. This can indicate that the .mat file is corrupted.

在Matlab中,我可以毫无问题地打开该文件。我也尝试过再次保存它,但是什么也没有改变...您能帮我吗?

此处:https : //drive.google.com/drive/folders/0B3vXKJ_zYaCJanZfOUVIcGJyR0E, 您可以找到以相同方式保存的2个文件。

我可以打开part_000,但不能打开part_001。...为什么?:(

python matlab scipy

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

连接熊猫数据帧时,整数变为浮点数

我有 2 个熊猫数据框:

df1 是一个空数据框: import pandas as pd import numpy as np

df1 = pd.DataFrame(columns=['Start','End','Duration'])

df1
Out[1]:
Empty DataFrame
Columns: [Start, End, Duration]
Index: []
Run Code Online (Sandbox Code Playgroud)

df2 包含:

df2 = pd.DataFrame(np.array([None] * 3).reshape(-1,3),columns=['Start','End','Duration'])
df2['Start'] = 483
df2['End'] = 523
df2['Duration'] = 0.8

df2
Out[2]: 
       Start  End  Duration
    0    483  523      0.8


df2['Start']
Out[3]: 
0    483
Name: Start, dtype: int64
Run Code Online (Sandbox Code Playgroud)

我想连接 2 个数据帧:

df1= pd.concat([df1, df2], ignore_index=True)[df1.columns.tolist()]
Run Code Online (Sandbox Code Playgroud)

df1 是:

df1
Out[4]: 
   Start    End  Duration
0  483.0  523.0    0.8
Run Code Online (Sandbox Code Playgroud)

正如你现在看到的“开始”和“结束”是浮动的......有没有办法让它们保持完整?

python dataframe pandas

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

conda 不被识别为内部或外部命令、可运行程序或批处理文件

我正在使用以下方法更新 pandas(在 Windows 7 上):

conda update pandas
Run Code Online (Sandbox Code Playgroud)

我在更新时不小心关闭了命令窗口。现在我无法启动spyder,如果我在命令窗口中输入conda,我会得到:

"conda is not recognized as an internal or external command operable program or batch file"
Run Code Online (Sandbox Code Playgroud)

如果我输入spyder --show=console 我得到

from PyQt5.Qtwidgets import * 
importerror: DLL load failed: The specific module could not be found
Run Code Online (Sandbox Code Playgroud)

知道如何解决这个问题吗?

python spyder anaconda conda

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

根据条件合并行pandas数据帧

嗨有一个数据帧 df

包含一组事件(行).

df = pd.DataFrame(data=[[1, 2,   7, 10],
                   [10, 22, 1, 30],
                   [30, 42, 2, 10],  
                   [100,142, 22,1],
                   [143, 152, 2, 10],
                   [160, 162, 12, 11]],columns=['Start','End','Value1','Value2'])

 df
Out[15]: 
   Start  End  Value1  Value2
0      1    2       7      10
1     10   22       1      30
2     30   42       2      10
3    100  142      22       1
4    143  152       2      10
5    160  162      12      11
Run Code Online (Sandbox Code Playgroud)

如果2(或更多)连续事件是<= 10相距甚远我想合并2(或更多)事件(即使用第一事件的开始,最后的端部和在值1和值2的值相加).

在上面的例子中,df变为:

 df
Out[15]: 
   Start  End  Value1  Value2
0      1   42      10      50
1    100  162 …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

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

无法将scikit-learn更新到版本0.20

我正在尝试通过运行将sklearn从0.19.2更新到0.20

conda update scikit-learn
Run Code Online (Sandbox Code Playgroud)

在anaconda提示符下,但它不会更新软件包...我得到

Solving environment: done

# All requested packages already installed.
Run Code Online (Sandbox Code Playgroud)

我也试过

conda update conda
Run Code Online (Sandbox Code Playgroud)

然后conda update scikit-learn我又得到了(两个更新)

Solving environment: done

# All requested packages already installed.
Run Code Online (Sandbox Code Playgroud)

如果我检查sklearn版本,仍然可以

import sklearn
sklearn.__version__

 '0.19.2'
Run Code Online (Sandbox Code Playgroud)

如果我型conda info我得到

     active environment : base
    active env location : C:\ProgramData\Anaconda3
            shell level : 1
       user config file : C:\Users\xxx\.condarc
 populated config files :
          conda version : 4.5.11
    conda-build version : 3.10.5
         python version : 3.6.5.final.0
       base environment : C:\ProgramData\Anaconda3  (writable) …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn anaconda conda

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