17

If you properly isolate your test set such that it doesn't affect training, you should only look at the test set accuracy. Here are some of my remarks: Having your model being really good on the train set is not a bad thing in itself. On the contrary, if the test accuracy is identical, you want to pick the model with the better train accuracy. You want to ...


8

See the docs: You need to add an intercept to statsmodels manually, while it is added automatically in sklearn. import altair as alt import numpy as np import pandas as pd from sklearn.linear_model import LinearRegression import statsmodels.api as sm np.random.seed(0) data = pd.DataFrame({ 'Date': pd.date_range('1990-01-01', freq='D', periods=50), 'NDVI': ...


3

Yes. With y being a 1d array of integers (as after LabelEncoder), sklearn treats it as a multiclass classification problem. With y being a 2d binary array (as after LabelBinarizer), sklearn treats it as a multilabel problem. Presumably, the multilabel model is predicting no labels for some of the rows. (With your actual data not being multilabel, the sum ...


3

I've got the same issue today, and it's a shame your post got no answers. I think this question is not well addressed in the sklearn documentation. I can show you my workaround to this issue: headers = X.columns.values X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) empty_train_columns = [] for col in X_train.columns.values: # ...


3

From this kaggle discussion, the classification algorithms from scikit-learn that support sparse matrices are at least: linear_model.LogisticRegression() svm.SVR() svm.NuSVR() naive_bayes.MultinomialNB() naive_bayes.BernoulliNB() linear_model.PassiveAggressiveClassifier() linear_model.Perceptron() linear_model.Ridge() linear_model.Lasso() linear_model....


2

You can refactor your code to make this issue easier to investigate. Something like this: nbrs = NearestNeighbors(n_neighbors=1, n_jobs=-1).fit(tfidf) orgs = list(set(names['VariationName'].values)) queryTFIDF_ = vectorizer.transform(orgs) distances, indices = nbrs.kneighbors(queryTFIDF_) matches = pd.DataFrame(columns=['Match confidence (lower is ...


2

Here I go with a worked example for answering mainly your first 2 questions, with some code based on this scikit-learn example. Let's generate a rough parabola as follows: import numpy as np import matplotlib.pyplot as plt def f(x): """ function to approximate by polynomial interpolation""" return np.square(x) # generate points used to plot x_plot ...


2

"Linear regression" (aka. "ordinary least squares", OLS) refers to the type of estimator. Linear here means that you minimise the sum of squared residuals for a given (linear additive) regression equation. You can write a simple model: $$y = \beta_0 + \beta_1 x_1 + u. $$ This would fit a linear function with intercept $\beta_0$ and slope $\beta_1$. So the ...


2

It seems to me you did not understand what polynomial regression is. Generally speaking, when you apply polynomial regression, you add a new feature for each power of x of the polynom. When you write : polynomial_features= PolynomialFeatures(degree=2) that means you have degree=2, that means that you add to your training dataset a new feature filled with x^...


2

Based on your screenshot, it's quite clear that the accuracy isn't 0.0 since the first two predictions match the true labels. So something must be wrong with how the accuracy is calculated. If you go to sklearn's documentation, you'll see that accuracy_score requires 1-d arrays while it seems that you are feeding it 2-d arrays. My guess is that right now, ...


2

In addition to @ncasas 's links, Here is the full list of classification/regression/feature selection and few more by David Ziganto's blog. Which I referred last week- https://dziganto.github.io/Sparse-Matrices-For-Efficient-Machine-Learning/ Also, from sk-learn documentation, they have example code for text classification which is using few of models. ...


2

value represents the number of items in each class. If you look at the top node, you should view it as: There are: 35100 samples of class 0 16288 samples of class 1 which sums up to 51388 samples total


2

Would try to answer based on experience and understandings of parallel computing in production for DS/ML models: Answer to your questions as high level: Does the simple program above give you better performance with increasing n_jobs when you run it? answer: Yes and can be seen bellow in results. On what OS / setup? answer: OS:ubuntu, 2xCPUsx16Cores+...


2

When I ran your script, I got the same impression, that n_jobs was hurting you performance. However, you have to consider that parallelizing the cross-validation would only benefit if you have more data samples. With few data, the communication overhead indeed is more expensive than the processing cost involved on the task. I tried your script with more ...


2

The best option for encoding - OneHot, because if you use Label encoding you indicate that categorical values are comparable(for example label 1 < label 2), which most probably it's not true. One hot encoding create columns for each specific value in the column, moreover, these columns are linearly independent, so you don't create fake order between ...


1

It depends exactly on which kind of patterns you are talking about. Are they deterministic? That is, they are all the same, so you want to get everything after Dear, or before Att / Best Regards, you can explore regular expression patterns. In python, you can use re library: https://docs.python.org/3/library/re.html There are books about regular ...


1

You generally shouldn't apply resampling to the test set (although there are some differing opinions on whether to do so on various levels of validation data). imblearn has its own version of the pipeline to accomplish this; in particular, the pipeline docs say: The samplers are only applied during fit.


1

You could use class KerasClassifier from keras.wrappers.scikit_learn, which wraps a Keras model in a scikit-learn interface, so that it can be used like other scikit-learn models and then you could evaluate it with scikit-learn's scoring functions, e.g.: from keras.wrappers.scikit_learn import KerasClassifier from sklearn.metrics import roc_curve, auc ...


1

The error is self-explanatory. You provide the model with only 3 features whereas it needs 12 features. In model.py you select 3 features from the dataset, indeed. However, you apply one-hot encoding that creates new columns. Each new column describes only one category and contains values 0 and 1: whether this category is observed in a sample or not. And the ...


1

If you carry out grid search cross validation on your X data (containing 800k samples), you do not need to make another train_test_split before fitting your model, since the grid search CV strategy already makes several splits (as many as the 'cv' parameter value, check it out here), and then you validate with data never seen before by the model (i.e. the ...


1

Your hyperparameters are chosen based on the whole set of examples, and thus there is a leakage of information of the test set into the model. The validation will, therefore, be too optimistic (as you suspected). What could be fixed is instead of: clf.fit(X, y) just use clf.fit(x_train, y_train) As you suggested yourself already. After that line, ...


1

The description says- ".................the features generated by each transformer will be concatenated to form a single feature space" Based on this I would not expect it to "reduce" the number of columns. On top of my mind, another pipeline which computes on dates column and feeds its output to numeric column transformation in columnTransformation.


1

LabelEncoder is meant for the labels (target, dependent variable), not for the features. OrdinalEncoder can be used for features, and so can take a 2d array rather than the 1d array LabelEncoder requires, and so you can use a single transformer for all your categorical columns. (You can use a ColumnTransformer to select those categorical columns, if you ...


1

As per the documentation, whenever the transformer expects a 1D array as input, the columns were specified as a string ("xxx"). For the transformers which expects 2D data, we need to specify the column as a list of strings (["xxx"]). so the code below will work. ## Important: i have passed the columns a string to CV and list of columns to OHE transformer=...


1

In terms of evaluation, the best you can do with a very small amount of data is repeating $k$-fold cross-validation many times (i.e. very large $k$), and consider the whole distribution of scores as the performance (in particular take into account the variance across folds). It's going to be difficult anyway to obtain a reliable measure of performance with ...


1

A fundamentally linear model like logistic regression will never work well, because its assumptions are not at all true for your data set. It presumes that probability (OK, really, log odds) of being positive or negative changes linearly in each input, but, it alternates with each integer value in your input. KNN's assumption likewise does not match. For ...


1

I've done a bit of searching and have actually found a solution to this using tsfresh. You can find the sklearn transformers here: https://tsfresh.readthedocs.io/en/latest/text/sklearn_transformers.html Here is the code snippet from the example. pipeline = Pipeline( [ ('augmenter', RelevantFeatureAugmenter(column_id='id', column_sort='time')), ...


1

So order here means how many possible combinations of labels you want to compare (e.g., order=1 would by how often does each label appear, order=2 would be how often any two combinations of labels appear with values like 5,5 meaning "rows that only have a label in index 5 and no other label, and where the max order should be the number of labels you have --> ...


Only top voted, non community-wiki answers of a minimum length are eligible