非常强大的开源数据挖掘工具SPMF的文档分别列出了它们:
http://www.philippe-fournier-viger.com/spmf/index.php?link=algorithms.php
有人知道为什么吗?
我正在尝试StratifiedKFold创建训练/测试/验证分割,以便在非 sklearn 机器学习工作流程中使用。因此,DataFrame 需要被拆分并保持这种状态。
我尝试按照以下方式执行此操作,.values因为我正在传递 pandas DataFrames:
skf = StratifiedKFold(n_splits=3, shuffle=False)
skf.get_n_splits(X, y)
for train_index, test_index, valid_index in skf.split(X.values, y.values):
print("TRAIN:", train_index, "TEST:", test_index, "VALID:", valid_index)
X_train, X_test, X_valid = X.values[train_index], X.values[test_index], X.values[valid_index]
y_train, y_test, y_valid = y.values[train_index], y.values[test_index], y.values[valid_index]
Run Code Online (Sandbox Code Playgroud)
这失败了:
skf = StratifiedKFold(n_splits=3, shuffle=False)
skf.get_n_splits(X, y)
for train_index, test_index, valid_index in skf.split(X.values, y.values):
print("TRAIN:", train_index, "TEST:", test_index, "VALID:", valid_index)
X_train, X_test, X_valid = X.values[train_index], X.values[test_index], X.values[valid_index]
y_train, y_test, y_valid = y.values[train_index], y.values[test_index], y.values[valid_index]
Run Code Online (Sandbox Code Playgroud)
我通读了所有sklearn …
我是数据科学和分析的新手。在 Kaggle 上研究了很多内核之后,我制作了一个预测房产价格的模型。我已经使用我的训练数据测试了这个模型,但现在我想在我的测试数据上运行它。我有一个 test.csv 文件,我想使用它。我怎么做?我之前对训练数据集做了什么:
#loading my train dataset into python
train = pd.read_csv('/Users/sohaib/Downloads/test.csv')
#factors that will predict the price
train_pr = ['OverallQual','GrLivArea','GarageCars','TotalBsmtSF','FullBath','YearBuilt']
#set my model to DecisionTree
model = DecisionTreeRegressor()
#set prediction data to factors that will predict, and set target to SalePrice
prdata = train[train_pr]
target = train.SalePrice
#fitting model with prediction data and telling it my target
model.fit(prdata, target)
model.predict(prdata.head())
Run Code Online (Sandbox Code Playgroud)
现在我尝试做的是,复制整个代码,并将“train”更改为“test”,将“predate”更改为“testprdata”,我认为它会起作用,但遗憾的是没有。我知道我做错了什么,我不知道那是什么。
如果问题的标题不是很清楚,我很抱歉,我无法用一句话概括问题。
以下是用于解释的简化数据集。基本上,训练集中的类别数量远大于测试集中的类别数量,因此 OneHotEncoding 后测试和训练集中的列数存在差异。我该如何处理这个问题?
训练集
+-------+----------+
| Value | Category |
+-------+----------+
| 100 | SE1 |
+-------+----------+
| 200 | SE2 |
+-------+----------+
| 300 | SE3 |
+-------+----------+
Run Code Online (Sandbox Code Playgroud)
OneHotEncoding后的训练集
+-------+-----------+-----------+-----------+
| Value | DummyCat1 | DummyCat2 | DummyCat3 |
+-------+-----------+-----------+-----------+
| 100 | 1 | 0 | 0 |
+-------+-----------+-----------+-----------+
| 200 | 0 | 1 | 0 |
+-------+-----------+-----------+-----------+
| 300 | 0 | 0 | 1 |
+-------+-----------+-----------+-----------+
Run Code Online (Sandbox Code Playgroud)
测试装置
+-------+----------+
| Value | Category |
+-------+----------+ …Run Code Online (Sandbox Code Playgroud) 假设我有数据帧df1,其中包括两列 - A和B.A值表示较低范围,B值表示较高范围.
A B
10.5 20.5
30.5 40.5
50.5 60.5
Run Code Online (Sandbox Code Playgroud)
我有另一个数据框,其中包括两列 - 包含不同数字范围的C&D.
C D
12.34 15.90
13.68 19.13
33.5 35.60
35.12 38.76
50.6 59.1
Run Code Online (Sandbox Code Playgroud)
现在我想列出df2中属于df1组(在低范围和高范围之间)的所有对.
最终输出应该是这样的 -
Key Values
(10.5, 20.5) [(12.34, 15.90), (13.68, 19.13)]
(30.5, 40.5) [(33.5, 35.60), (35.12, 38.76)]
(50.5, 60.5) [(50.6, 59.1)]
Run Code Online (Sandbox Code Playgroud)
解决方案应该是高效的,因为我有5000组范围和85000个不同范围的数字.
如果数据集包含一些特征,其中一些是分类变量,另一些是连续变量,则决策树比线性回归更好,因为树可以根据分类变量准确地划分数据。线性回归是否有优于随机森林的情况?
我正在尝试在seaborn中为4个箱线图创建一个4x4 FacetGrid,每个箱线图根据虹膜数据集中的虹膜种类分为3个箱线图。目前,我的代码如下所示:
sns.set(style="whitegrid")
iris_vis = sns.load_dataset("iris")
fig, axes = plt.subplots(2, 2)
ax = sns.boxplot(x="Species", y="SepalLengthCm", data=iris, orient='v',
ax=axes[0])
ax = sns.boxplot(x="Species", y="SepalWidthCm", data=iris, orient='v',
ax=axes[1])
ax = sns.boxplot(x="Species", y="PetalLengthCm", data=iris, orient='v',
ax=axes[2])
ax = sns.boxplot(x="Species", y="PetalWidthCm", data=iris, orient='v',
ax=axes[3])
Run Code Online (Sandbox Code Playgroud)
但是,我从翻译中收到此错误:
AttributeError: 'numpy.ndarray' object has no attribute 'boxplot'
Run Code Online (Sandbox Code Playgroud)
我对属性错误到底在哪里感到困惑。我需要改变什么?
import pyspark
from pyspark.sql import SparkSession
from pyspark.conf import SparkConf
import findspark
from pyspark.sql.functions import countDistinct
spark = SparkSession.builder \
.master("local[*]") \
.appName("usres mobile related information analysis") \
.config("spark.submit.deployMode", "client") \
.config("spark.executor.memory","3g") \
.config("spark.driver.maxResultSize", "1g") \
.config("spark.executor.pyspark.memory","3g") \
.enableHiveSupport() \
.getOrCreate()
Run Code Online (Sandbox Code Playgroud)
handset_info = ora_tmp.select('some_value','some_value','some_value','some_value','some_value','some_value','some_value')
我用 3gb 执行内存和 3gb 执行 pyspark 内存配置 spark。我的数据库有超过 7000 万行。显示我调用
handset_info.show()
Run Code Online (Sandbox Code Playgroud)
方法是在 2-5 秒之间显示前 20 行。但是当我尝试运行以下代码时
mobile_info_df = handset_info.limit(30)
mobile_info_df.show()
Run Code Online (Sandbox Code Playgroud)
显示前 30 行需要太多时间(3-4 小时)。花那么多时间是否合乎逻辑。我的配置有问题吗。我的笔记本电脑的配置是-
我正在使用来自Kaggle challange 的MNIST 数据集,并且在数据预处理方面遇到了麻烦。此外,我不知道什么是最佳实践,想知道您是否可以就此提出建议。
免责声明:我不能只使用 torchvision.datasets.mnist 因为我需要使用 Kaggle 的数据进行训练和提交。
在本教程中,建议创建一个从文件加载 .pt 张量的 Dataset 对象,以充分利用 GPU。为了实现这一点,我需要加载 Kaggle 提供的 csv 数据并将其保存为 .pt 文件:
import pandas as pd
import torch
import numpy as np
# import data
digits_train = pd.read_csv('data/train.csv')
train_tensor = torch.tensor(digits_train.drop(label, axis=1).to_numpy(), dtype=torch.int)
labels_tensor = torch.tensor(digits_train[label].to_numpy())
for i in range(train_tensor.shape[0]):
torch.save(train_tensor[i], "data/train-" + str(i) + ".pt")
Run Code Online (Sandbox Code Playgroud)
每个train_tensor[i].shape是torch.Size([1, 784])
但是,每个此类 .pt 文件的大小约为 130MB。相同大小的张量,随机生成整数,大小为 6.6kB。为什么这些张量如此巨大,我该如何减小它们的大小?
数据集是 42 000 个样本。我什至应该打扰批处理这些数据吗?我是否应该费心将张量保存到单独的文件中,而不是将它们全部加载到 RAM 中然后分批?这里最好的方法是什么?
假设我有以下数据框:

我检查了文档,但它仅基于单列。
可重现的代码:
x = np.random.normal(100,5,100)
data = pd.DataFrame(x)
epsilon = 10
data.columns = ['x']
data['lower'] = x - epsilon
data['upper'] = x + epsilon
data
Run Code Online (Sandbox Code Playgroud)
我实际上喜欢使用 altair,因为我喜欢它的交互性。
data-science ×10
python ×7
scikit-learn ×3
pandas ×2
python-3.x ×2
altair ×1
bigdata ×1
boxplot ×1
data-mining ×1
kaggle ×1
performance ×1
pyspark ×1
pytorch ×1
seaborn ×1