我有80%分类变量的机器学习分类问题.如果我想使用某种分类器进行分类,我必须使用一个热编码吗?我可以在没有编码的情况下将数据传递给分类器吗?
我正在尝试执行以下功能选择:
我读了火车文件:
num_rows_to_read = 10000
train_small = pd.read_csv("../../dataset/train.csv", nrows=num_rows_to_read)
Run Code Online (Sandbox Code Playgroud)我将分类要素的类型更改为"类别":
non_categorial_features = ['orig_destination_distance',
'srch_adults_cnt',
'srch_children_cnt',
'srch_rm_cnt',
'cnt']
for categorical_feature in list(train_small.columns):
if categorical_feature not in non_categorial_features:
train_small[categorical_feature] = train_small[categorical_feature].astype('category')
Run Code Online (Sandbox Code Playgroud)我使用一个热编码:
train_small_with_dummies = pd.get_dummies(train_small, sparse=True)
Run Code Online (Sandbox Code Playgroud)问题是第3部分经常卡住,虽然我使用的是强机.
因此,在没有热编码的情况下,我无法进行任何特征选择,以确定特征的重要性.
您有什么推荐的吗?
我正在写一个.csv文件:
my_data_frame.to_cav("some_path")
Run Code Online (Sandbox Code Playgroud)
尝试使用以下内容读取文件时:
pd.read_csv("some_path")
Run Code Online (Sandbox Code Playgroud)
我可以说,添加了一个未命名的列.我该如何解决这个问题?
我有以下numpy矩阵:
array([[64, 22,],
[58, 64],
[42, 31])
Run Code Online (Sandbox Code Playgroud)
我希望得到以下内容:
pd.DataFrame({'one':"64 22", 'two':"42 31"})
Run Code Online (Sandbox Code Playgroud)
我的目的是将numpy.array中的每一行转换为将用于pandas数据帧的字符串.是否有一些内置的熊猫功能来救援?
我正在使用Linux机器,并且有两个屏幕。我还使用远程桌面应用程序在某些远程Linux机器上工作。
我连接到远程计算机,然后按Ctrl + Alt + F,以使远程屏幕获得控制权。
我的问题是Ctrl + Alt + F-使用两个屏幕时,只能将它们变成一个大屏幕,而要拥有两个屏幕我将能够独立打开窗口。
如何制作独立屏幕?
我有以下内容:
x = pd.DataFrame({'a':[1,5,5], 'b':[7,0,7]})
Run Code Online (Sandbox Code Playgroud)
对于每一行,我想获取满足其值大于某个值(假设大于 4)条件的第一列的索引。
在本例中,答案为 1(对应第一行中值 7 的索引)和 0(对应第二行中值 5 的索引)和 1(对应于值 5 的索引)第三行5)。这意味着答案是[1,0,0]。
我用 apply 方法尝试过:
def get_values_from_row(row, th=0.9):
"""Get a list of column names that meet some condition that their values are larger than a threshold.
Args:
row(pd.DataFrame): a row.
th(float): the threshold.
Returns:
string. contains the columns that it's value met the condition.
"""
return row[row > th].index.tolist()[0]
Run Code Online (Sandbox Code Playgroud)
它可以工作,但是我有一个很大的数据集,而且速度很慢。有什么更好的选择。
我试着搜索python路径,但那不起作用.
如何在PyCharm中使用anaconda python解释器?
我有一个超过一些值的循环.我有一个字典,它的键是循环迭代的值.
我不能改变外循环.
for i in range(1, 1000000000000):
if i in my_dict.keys():
func()
other_func(i)
Run Code Online (Sandbox Code Playgroud)
:中的每个元素都my_dict.keys()
出现在range(1, 1000000000000)
.但是,元素的数量my_dict.keys()
远小于迭代次数.
问题是每个检查都很费时间.处理这个问题的好方法是什么?