regression

Find and draw regression plane to a set of points

ⅰ亾dé卋堺 提交于 2020-01-12 01:53:05
问题 I want to fit a plane to some data points and draw it. My current code is this: import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt points = [(1.1,2.1,8.1), (3.2,4.2,8.0), (5.3,1.3,8.2), (3.4,2.4,8.3), (1.5,4.5,8.0)] xs, ys, zs = zip(*points) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(xs, ys, zs) point = np.array([0.0, 0.0, 8.1]) normal = np.array([0.0, 0.0, 1.0]) d = -point.dot(normal) xx, yy = np.meshgrid([-5,10], [-5,10])

Linear model singular because of large integer datetime in R?

前提是你 提交于 2020-01-11 12:09:11
问题 Simple regression of random normal on date fails, but identical data with small integers instead of dates works as expected. # Example dataset with 100 observations at 2 second intervals. set.seed(1) df <- data.frame(x=as.POSIXct("2017-03-14 09:00:00") + seq(0, 199, 2), y=rnorm(100)) #> head(df) # x y # 1 2017-03-14 09:00:00 -0.6264538 # 2 2017-03-14 09:00:02 0.1836433 # 3 2017-03-14 09:00:04 -0.8356286 # Simple regression model. m <- lm(y ~ x, data=df) The slope is missing due to

Keras regression clip values

纵饮孤独 提交于 2020-01-11 09:25:10
问题 I want to clip values, how could I do that? I tried using this: from keras.backend.tensorflow_backend import clip from keras.layers.core import Lambda ... model.add(Dense(1)) model.add(Activation('linear')) model.add(Lambda(lambda x: clip(x, min_value=200, max_value=1000))) But it does not matter where I put my Lambda+clip, it does not affect anything? 回答1: It actually has to be implemented as loss, at the model.compile step. from keras import backend as K def clipped_mse(y_true, y_pred):

Print or capturing multiple objects in R

99封情书 提交于 2020-01-11 06:42:11
问题 I have multiple regressions in an R script and want to append the regression summaries to a single text file output. I know I can use the following code to do this for one regression summary, but how would I do this for multiple? rpt1 <- summary(fit) capture.output(rpt1, file = "results.txt") I would prefer not to have to use this multiple times in the same script (for rpt1, rpt2, etc.), and thus have separate text files for each result. I'm sure this is easy, but I'm still learning the R

What is the difference between xgb.train and xgb.XGBRegressor (or xgb.XGBClassifier)?

十年热恋 提交于 2020-01-10 14:10:11
问题 I already know " xgboost.XGBRegressor is a Scikit-Learn Wrapper interface for XGBoost." But do they have any other difference? 回答1: xgboost.train is the low-level API to train the model via gradient boosting method. xgboost.XGBRegressor and xgboost.XGBClassifier are the wrappers ( Scikit-Learn-like wrappers , as they call it) that prepare the DMatrix and pass in the corresponding objective function and parameters. In the end, the fit call simply boils down to: self._Booster = train(params,

Distinguishing overfitting vs good prediction

最后都变了- 提交于 2020-01-09 12:18:48
问题 These are questions on how to calculate & reduce overfitting in machine learning. I think many new to machine learning will have the same questions, so I tried to be clear with my examples and questions in hope that answers here can help others. I have a very small sample of texts and I'm trying to predict values associated with them. I've used sklearn to calculate tf-idf, and insert those into a regression model for prediction. This gives me 26 samples with 6323 features - not a lot.. I know

Distinguishing overfitting vs good prediction

泄露秘密 提交于 2020-01-09 12:17:18
问题 These are questions on how to calculate & reduce overfitting in machine learning. I think many new to machine learning will have the same questions, so I tried to be clear with my examples and questions in hope that answers here can help others. I have a very small sample of texts and I'm trying to predict values associated with them. I've used sklearn to calculate tf-idf, and insert those into a regression model for prediction. This gives me 26 samples with 6323 features - not a lot.. I know

Different Robust Standard Errors of Logit Regression in Stata and R

雨燕双飞 提交于 2020-01-09 06:36:12
问题 I am trying to replicate a logit regression from Stata to R. In Stata I use the option "robust" to have the robust standard error (heteroscedasticity-consistent standard error). I am able to replicate the exactly same coefficients from Stata, but I am not able to have the same robust standard error with the package "sandwich". I have tried some OLS linear regression examples; it seems like the sandwich estimators of R and Stata give me the same robust standard error for OLS. Does anybody know

How to debug “contrasts can be applied only to factors with 2 or more levels” error?

偶尔善良 提交于 2020-01-07 08:02:07
问题 Here are all the variables I'm working with: str(ad.train) $ Date : Factor w/ 427 levels "2012-03-24","2012-03-29",..: 4 7 12 14 19 21 24 29 31 34 ... $ Team : Factor w/ 18 levels "Adelaide","Brisbane Lions",..: 1 1 1 1 1 1 1 1 1 1 ... $ Season : int 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ... $ Round : Factor w/ 28 levels "EF","GF","PF",..: 5 16 21 22 23 24 25 26 27 6 ... $ Score : int 137 82 84 96 110 99 122 124 49 111 ... $ Margin : int 69 18 -56 46 19 5 50 69 -26 29 ... $

Least square optimization (of matrices) in R

北城余情 提交于 2020-01-07 06:49:12
问题 Yesterday I asked a question about least square optimization in R and it turned out that lm function is the thing that I was looking for. On the other hand, now I have an other least square optimization question and I am wondering if lm could also solve this problem, or if not, how it can be handled in R. I have fixed matrices B (of dimension n x m) and V (of dimension n x n), I am looking for an m -long vector u such that sum( ( V - ( B %*% diag(u) %*% t(B)) )^2 ) is minimized. 回答1: 1) lm