- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里读过 https://towardsdatascience.com/do-decision-trees-need-feature-scaling-97809eaa60c6并观看 https://www.youtube.com/watch?v=nmBqnKSSKfM&ab_channel=KrishNaik视频表明您不需要使用标准缩放器进行决策树机器学习。
但是,发生在我的代码上的情况恰恰相反。这是我试图运行的代码。
# importing libraries
import numpy as nm
import matplotlib.pyplot as mpl
import pandas as pd
#importing datasets
data_set= pd.read_csv('Social_Network_Ads.csv')
#Extracting Independent and dependent Variable
x= data_set.iloc[:, [2,3]].values
y= data_set.iloc[:, 4].values
# Splitting the dataset into training and test set.
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.25, random_state=0)
#feature Scaling
from sklearn.preprocessing import StandardScaler
st_x= StandardScaler()
x_train= st_x.fit_transform(x_train)
x_test= st_x.transform(x_test)
#Fitting Decision Tree classifier to the training set
from sklearn.tree import DecisionTreeClassifier
classifier= DecisionTreeClassifier(criterion='entropy', random_state=0)
classifier.fit(x_train, y_train)
我继续尝试将数据可视化的部分的问题。这是代码。
#Visulaizing the trianing set result
from matplotlib.colors import ListedColormap
x_set,y_set = x_train, y_train
x1, x2 = nm.meshgrid(nm.arange(start = x_set[:, 0].min() - 1, stop = x_set[:, 0].max() + 1, step =0.01),
nm.arange(start = x_set[:, 1].min() - 1, stop = x_set[:, 1].max() + 1, step = 0.01))
mpl.contourf(x1, x2, classifier.predict(nm.array([x1.ravel(), x2.ravel()]).T).reshape(x1.shape),
alpha = 0.75, cmap = ListedColormap(('purple','green' )))
mpl.xlim(x1.min(), x1.max())
mpl.ylim(x2.min(), x2.max())
for i, j in enumerate(nm.unique(y_set)):
mpl.scatter(x_set[y_set == j, 0], x_set[y_set == j, 1], c = ListedColormap(('purple', 'green'))(i), label = j)
mpl.title('Decision Tree Algorithm (Training set)')
mpl.xlabel('Age')
mpl.ylabel('Estimated Salary')
mpl.legend()
mpl.show()
输出成功
如果我使用 StandardScaler 运行它 .该图显示得很好。但是,当我对 StandardScaler 部分进行散列(评论)时,它声明了
内存错误。
MemoryError Traceback (most recent call last)
<ipython-input-8-1282bf709e27> in <module>
3 x_set,y_set = x_train, y_train
4 x1, x2 = nm.meshgrid(nm.arange(start = x_set[:, 0].min() - 1, stop = x_set[:, 0].max() + 1, step =0.01),
----> 5 nm.arange(start = x_set[:, 1].min() - 1, stop = x_set[:, 1].max() + 1, step = 0.01))
6 mpl.contourf(x1, x2, classifier.predict(nm.array([x1.ravel(), x2.ravel()]).T).reshape(x1.shape),
7 alpha = 0.75, cmap = ListedColormap(('purple','green' )))
~\Anaconda3\lib\site-packages\numpy\lib\function_base.py in meshgrid(*xi, **kwargs)
4209
4210 if copy_:
-> 4211 output = [x.copy() for x in output]
4212
4213 return output
~\Anaconda3\lib\site-packages\numpy\lib\function_base.py in <listcomp>(.0)
4209
4210 if copy_:
-> 4211 output = [x.copy() for x in output]
4212
4213 return output
MemoryError:
错误只发生在可视化部分;在代码的另一部分,这种预测在没有标准缩放器的情况下也能很好地工作。
最佳答案
决策树可以在没有标准缩放器和标准缩放器的情况下工作。这里要注意的重要一点是,缩放数据不会影响决策树模型的性能。
如果您之后绘制数据,尽管我想您不想绘制缩放数据,而是绘制原始数据;因此你的问题。
我能想到的最简单的解决方案是通过 sparse=True
作为 numpy.meshgrid
的参数因为这似乎是在您的回溯中引发错误的原因。在过去的问题 here. 中对此有一些详细信息
因此适用于您的问题,这意味着您更改了这一行:
nm.meshgrid(
nm.arange(start=x_set[:, 0].min() - 1, stop=x_set[:, 0].max() + 1, step=0.01),
nm.arange(start=x_set[:, 1].min() - 1, stop=x_set[:, 1].max() + 1, step=0.01),
)
到
nm.meshgrid(
nm.arange(start=x_set[:, 0].min() - 1, stop=x_set[:, 0].max() + 1, step=0.01),
nm.arange(start=x_set[:, 1].min() - 1, stop=x_set[:, 1].max() + 1, step=0.01),
sparse=True,
)
关于python - 如果不使用 Standard Scaler 会出现内存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68881786/
JavaScript Standard Style 翻译: Português, Spanish, 繁體中文, 简体中文 standard 规则列表,太多不必阅读。 了解 standard 的最好方式
我有一个 exec我使用 outputproperty 将其输出放入属性的任务属性。该命令可能会向 stderr 打印一些错误,我不希望将这些错误包含在输出中(因为输出被馈送到另一个命令中),而是要打
标题说明了一切 - 如何将 .NET 标准库标记为符合 CLS? 我用 C# 编写了一个简单的库,目标是 .NET Standard 1.0 框架。它包括两个枚举: public enum Align
我有一个写入错误输出的 PowerShell 脚本。该脚本可以简单如下: Write-Error 'foo' Start-Sleep -s 5 Write-Error 'bar' 我实际调用的脚本产生
对于完整的 .NET 项目,您可以在 Project Properties > Application tab > Assembly Information.. 中勾选一个框以使项目 COM 可见。
我将我的项目 ( https://github.com/MarkKhromov/The-Log) 迁移到 .NET Standard 2.0,但我的应用程序构建已损坏。我该如何解决这个问题? 我的解决
互联网上的许多文章都使用“标准输入/输出/错误流”术语好像每个术语都与使用的“标准输入/输出/错误设备”术语具有相同的含义在其他文章上。例如,很多文章说标准输出流默认是监视器,但可以重定向到文件、打印
我正在尝试从 https://github.com/go-yaml/yaml 导入 go-yaml ,并且我看到了 Google 未提供帮助的错误。 我运行了 go get gopkg.in/yaml
在列出 TimeZoneInfo.GetSystemTimeZones 返回的 TimeZoneInfo 的所有 Id 属性时,出现了两个版本的 EST:美国东部标准时间和东部标准时间。有什么区别?
问题: 如函数的 C 引用页所述,c16rtomb,来自 CPPReference ,在注释部分下: In C11 as published, unlike mbrtoc16, which conve
我想使用 go 语言从我的数据库中检索一些数据。这是我在文件 main.go 中的代码的开头 package main import ( _ "github.com/go-sql-driver
我一直在通过STM32F4发现进行音频项目,我注意到一件事,所有I2S标准仅适用于一个麦克风(取决于标准使用单独的位的哪个边缘)。例如飞利浦(Philips),MSB或LSB标准使用下降沿作为位触发,
有没有标准定义了 语法 和 语义的 汇编语言 ?与语言类似 C 有 ISO 标准和语言 C# 有 ECMA 标准?是只有一种标准,还是有更多标准? 我问是因为我noticed那个汇编语言代码看了不同
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它. 1年前关闭。 Improve this
我们正在内部构建API,并且经常传递带有多个值的参数。 他们使用:mysite.com?id=1&id=2&id=3 代替:mysite.com?id=1,2,3 我赞成第二种方法,但我很好奇是否真的
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
我认为有很多人不知道RFC(征求意见)。我知道它们在逻辑上是什么,但是有人能为新开发人员提供一个很好的描述吗?另外,共享一些有关如何使用和阅读它们的资源也很好。 最佳答案 这个术语来自互联网的前身AR
我找不到 Somaliland 的两个字母的国家/地区缩写,可能是因为它不是一个国家,而是正如维基百科所说:“一个未被承认的 self 宣布的事实上的主权国家,被国际承认为索马里的一个自治区”。尽管如
我正在编写一款蜜 jar 软件,该软件将对其交互进行大量记录,我计划记录纯文本 .log 文件。 我有两个问题,来自不太熟悉服务器日志方式的人。 首先,我该如何分解我的日志文件,我假设运行一个月后我不
我最近负责调试两个不同的程序,这两个程序最终至少需要共享一个 XML 解析脚本。一个是用 PureMVC 编写的,另一个是从头开始构建的。虽然最初从头开始编写是有意义的(它节省了大量内存,但内存问题已
我是一名优秀的程序员,十分优秀!