iris

graph.write_pdf(“iris.pdf”) AttributeError: 'list' object has no attribute 'write_pdf'

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My code is follow the class of machine learning of google.The two code are same.I don't know why it show error.May be the type of variable is error.But google's code is same to me.Who has ever had this problem? This is error [0 1 2] [0 1 2] Traceback (most recent call last): File "/media/joyce/oreo/python/machine_learn/VisualizingADecisionTree.py", line 34, in <module> graph.write_pdf("iris.pdf") AttributeError: 'list' object has no attribute 'write_pdf' [Finished in 0.4s with exit code 1] [shell_cmd: python -u "/media/joyce/oreo/python

Error in contrasts when defining a linear model in R

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I try to define my linear model in R as follows: lm1 <- lm(predictorvariable ~ x1+x2+x3, data=dataframe.df) I get the following error message: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels Is there any way to ignore this or fix it? Some of the variables are factors and some are not. 回答1: If your independent variable (RHS variable) is a factor or a character taking only one value then that type of error occurs. Example: iris data in R (model1 <- lm(Sepal

How to extract / subset an element from a list with the magrittr %&gt;% pipe?

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Since the introduction of the %>% operator in the magrittr package (and it's use in dplyr ), I have started to use this in my own work. One simple operation has me stumped, however. Specifically, this is the extraction (or subsetting) of elements from a list. An example: In base R I would use $ , [ or [[ to extract an element from a list: iris$Species iris [[ "Species" ]] I can achieve the same using the %>% pipe: iris %>% subset ( select = "Species" ) %>% head Species 1 setosa 2 setosa 3 setosa 4 setosa 5 setosa 6 setosa Or iris %

Transform a set of columns in a data.table

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: A data.table novice question. I would like to transform a set of columns in a data.table by applying a mathematical formula to them. The set of columns must exclude 1 or more of the total number of columns. In data.frame terms I would do: data ( iris ) head ( iris ) Sepal . Length Sepal . Width Petal . Length Petal . Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa iris [, - 5 ] <- iris [, - 5 ] * 1e3 head ( iris )

mutate_each / summarise_each in dplyr: how do I select certain columns and give new names to mutated columns?

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm a bit confused about the dplyr verb mutate_each. It's pretty straightforward to use the basic mutate to transform a column of data into, say, z-scores, and create a new column in your data.frame (here with the name z_score_data ): newDF % select(one_column) %>% mutate(z_score_data = one_column - (mean(one_column) / sd(one_column)) However, since I have many columns of data I'd like to transform, it appears I should probably use the mutate_each verb. newDF % mutate_each(funs(scale)) So far so good. But as of yet I haven't been able to

Easier way to plot the cumulative frequency distribution in ggplot?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm looking for an easier way to draw the cumulative distribution line in ggplot. I have some data whose histogram I can immediately display with qplot ( mydata , binwidth = 1 ); I found a way to do it at http://www.r-tutor.com/elementary-statistics/quantitative-data/cumulative-frequency-graph but it involves several steps and when exploring data it's time consuming. Is there a way to do it in a more straightforward way in ggplot, similar to how trend lines and confidence intervals can be added by specifying options? 回答1: There is

how to explain the decision tree from scikit-learn

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have two problems with understanding the result of decision tree from scikit-learn. For example, this is one of my decision trees: My question is that how I can use the tree? The first question is that: if a sample satisfied the condition, then it goes to the LEFT branch (if exists), otherwise it goes RIGHT . In my case, if a sample with X[7] > 63521.3984. Then the sample will go to the green box. Correct? The second question is that: when a sample reaches the leaf node, how can I know which category it belongs? In this example,

Evaluate Loss Function Value Getting From Training Set on Cross Validation Set

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am following Andrew NG instruction to evaluate the algorithm in Classification: Find the Loss Function of the Training Set. Compare it with the Loss Function of the Cross Validation. If both are close enough and small, go to next step (otherwise, there is bias or variance..etc). Make a prediction on the Test Set using the resulted Thetas(i.e. weights) produced from the previous step as a final confirmation. I am trying to apply this using Scikit-Learn Library, however, I am really lost there and sure that I am totally wrong (I didn't find

Lasso error in glmnet NA/NaN/Inf

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having an issue with glmnet in that I keep getting the error message "Error in elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian, : NA/NaN/Inf in foreign function call (arg 5) In addition: Warning message: In elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian, : NAs introduced by coercion" Below I can replicate the error with the 'iris' data set, but here is the simplified code for my particular data: vars <- as.matrix(ind.vars) lasso <- glmnet(vars, y=cup98$TARGET_D, alpha=1) Here is something you can easily

Adding a simple lm trend line to a ggplot boxplot

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When adding a linear model trend line to a boxplot using standard R graphics I use: boxplot(iris[,2]~iris[,1],col="LightBlue",main="Quartile1 (Rare)") modelQ1 However, when using this in ggplot2: a I get the following error: geom_smooth: Only one unique x value each group.Maybe you want aes(group = 1)? And the line does not appear on my plot. The models used in both of these scenarios are identical. If anyone could point out where I'm going wrong, that would be great. EDIT: Used the iris dataset as an example. 回答1: The error message is