# Tag Info

A linear model is in the form of: $y = a\cdot x_1 + b\cdot x_2 + c\cdot x_3.....$ Where $x_n$ is the feature and the letters a,b,c, is the coefficient. In your figure you are plotting the coefficient a,b,c... Lets say that you coefficients are $a=1$, $b=2$ and $c=10$ If you feature are $x_1=0$, $x_2=10$ and $x_3 = 1$ then your prediction will be $y = 1 \cdot ... 0 Is Random forest regression is a good method to approach this problem? Overall, decision trees tend not to be good regressors. But it can be that for your case it is working well. You need to evaluate the results corresponding to a metric and then compare different models. I like MAE in regression models because it's very intuitive. How can I improve the ... 0 One option is to scikit-learn's sklearn.impute.IterativeImputer. initial_strategy could be set to "most_frequent" which a useful way to model the Bernoulli distrubtion of the features. 1 how can I get from scikit learn BOTH the result and the probability? You can simply run both: The results will always be consistent because there is no randomness involved at the prediction stage, only at training stage. The computations required for predicting are not intensive, so I don't think there can be any major efficiency issue running it twice. ... 0 Firstly, lets suppose model omits the 'Size' as most significant feature, so what is implied here, having larger size or lower size of an app contribute to the rating? What If there is no ascending or descending order in the attribute, for instance, if the 'Category' is most significant, then what category contributed the most? Decision Tree splits the ... 0 I realized that when shuffling I did not set the replace parameter to True which prevented randomness from being inserted into the process. SEED_VALUE = 3 t_clf = Pipeline(steps=[('preprocessor', preprocessor), ('lgbm', LGBMClassifier(class_weight="balanced",random_state=SEED_VALUE, max_depth=20, min_child_samples=20, ... 2 Currently you're doing multiclass classification: find the most likely among N classes. Each class$C$probability indicates how likely class$C$is for the instance as opposed to any other class. This is why the probabilities sum to 1: in this setting, there is only one "correct" class, so two classes cannot both have high probability. Based on ... 0 As stated in the earlier comments, preprocessing both train and test set at the same time causes serious generalization error in the real life applications. So, I totally agree with you at this point. When it comes to scaler issue, the first thing that I came up with is that you can evaluate the importances of scaled features over the target value. Then, you ... 0 Ok first things first, I do not think it's a good idea to concatenate train and test set for anything and you are right in stating the problem of data leakage. Now as to getting different results when using scaler in cv is expected. This is because, for every iteration of cv, the data set changes. For example if cv = 3, then for the first iteration, it will ... 0 I had the same problem in one of the datasets I was using, and the answer is focus more on feature transformation. If you simply include all the features of your dataset for encoding, you would probably end up with more no of columns than you rows! I am positive there might be many features in you dataset that can be grouped in one column, some features can ... 0 This might be due to the fact that you are imputing missing values for one hot encoding but for pd.get_dummies you are not imputing. Hence you are getting worse results. Imputation without proper and careful domain as well as some stat knowledge usually worsens the performance. There are many alternatives to "imputation with mean" that might result ... 0 You can create hierarchical models. The first model in the hierarchy would only get the single feature. The next model in the hierarchy would get the other features. Scikit-learn does not natively support hierarchical modeling. You would have to write custom code. 1 The most intuitive way of visualizing your cluster results would be by using a linear projection like PCA. In this way you can visualize for example the first 3 components and assign a color to each point according to cluster_id Also important, you should in this case check the explained_variance as measure of how reliable the projection is, since you are ... 0 In your case X is not the future data. X is today data here as you try to predict tomorrow increase or decrease of value 1 or 0. So model1.predict(X) with X being today data, will give you the prediction 0 or 1. And this is it with your model 0 In theory, the very first thing to do should be fixing noises and seasonality. There are various ways of approaching the noises. If possible, try to understand the reason for noisy samples and extract the noise part from them manually. Or, use the smoothing algorithms to minimize the noises. In addition, you can create a dummy predictor variable that will be ... 0 Try: from sklearn.model_selection import train_test_split, GridSearchCV from sklearn.pipeline import Pipeline from sklearn.ensemble import RandomForestClassifier from sklearn.feature_extraction.text import TfidfVectorizer # features = ['description'] # target = 'ratingCategory' x_train, x_val, y_train, y_val = train_test_split( # train[features], ... 0 There is too few information to give a reasonable answer to this question, my thoughts is that the feature you are adding is a categorical variable presumably with a vast amount of different categories, what would increase the X matrix dimension (if using one hot encoding) thus increasing training time. 0 You can try to benchmarking the code. Python has robust benchmarking packages that track which parts of the code are taking the most time. 0 short answer, you cannot run your current model as described into the future. However, there is hope. When building a forecasting model, you're typically using an "autoregressive" model, which is predicting, for example, the price in the future based on the price in the past. The reason this works is you are both predicting the next value, and ... 0 That might not be possible within scikit-learn. Scikit-learn is not designed for extensive text processing. It might make more sense to define a data processing pipeline outside of scikit-learn. Then pass the outputs to a simplified version of TfidfVectorizer(). 0 You have completed the training phase. The next phase is commonly called prediction / inference. That is when already trained model predicts labels for data. Since you are using scikit-learn, you should the call .predict method. In your code, it will be model1.predict(X) where X is the numpy-like array that contains the data features. The result will be a ... 2 UPDATED As per your code, you have utilized River python package. OneHotEncoder PreviousImputer for handling missing/null values StandardScaler HoeffdingAdaptiveTreeClassifier machine learning model. In your code, you have utilized learn_one method which is stateless and actually does nothing, the next step you ideally need to do is to transform, ... 0 Scikit-learn's classification report has micro averaged F1 score: Micro average (averaging the total true positives, false negatives and false positives) is only shown for multi-label or multi-class with a subset of classes, because it corresponds to accuracy otherwise and would be the same for all metrics 3 You are currently using the fit_transform method on both your training dataset as well as your test set. This is incorrect since you should not fit the model on your test set as (depending on the model used) this would be overfitting, and it can give issues with dataset shapes when creating new columns based on the values in the data (count vectorizer, ... 0 Yes, extracting new features from existing ones is a common concept - one piece of the feature engineering process. There are different methods to handle missing values. In general, you don't want to lose any available information. There are different imputation techniques for missing values that have different efficiency depends on: the model you used, ... 3 The correct way of scaling both the features and the target in Python with Scikit-Learn for a regression problem would be wit pipelines as follow: from sklearn.linear_model import LinearRegression from sklearn.compose import TransformedTargetRegressor from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler tt = ... 2 Yes it is wrong to set shuffle=True. By shuffling the data you allow your model to learn properties of the data distribution that might appear only in the test time periods. For example, if you have a trend in the data, shuffling will 'help' you handle it. In a real-time scenario, you'll never have access to those properties of the distribution. 0 It's a really easy problem. Suppose you want to fit an imputer to your X_train and test data and keep the column names of X in the imputed results: imp = SimpleImputer() X_train = pd.DataFrame(imp.fit_transform(X_train), columns = X.columns) X_test = pd.DataFrame(imp.transform(X_test), columns = X.columns) 5 weights = 'distance' is in contrast to the default which is weights = 'uniform'. When weights are uniform, a simple majority vote of the nearest neighbors is used to assign cluster membership. When weights are distance weighted, the voting is proportional to the distance value. Nearby points will have a greater influence than more distance points (even if ... 0 Running this now, and updating to import GridSearchCV from model_selection, the code is: import sklearn import sklearn.ensemble import sklearn.metrics from sklearn.datasets import fetch_20newsgroups # from sklearn.grid_search import GridSearchCV from sklearn.model_selection import GridSearchCV categories = ['sci.med', 'soc.religion.christian'] ... 0 My two main remarks are: KNN being a distance based algorithm, scaling is a must! Otherwise the distance is distorted by the biggest feature value and small ones are not taken into account properly. You should try and properly scale or encode all the features. Could you tell how many features before and after encoding your get? You may need feature ... 1 Grid-search is used to find the optimal hyperparameters of a model, which results in the most accurate predictions. The grid.best_score gives the best optimal hyperparameters. This is calculated by the average of all the cross-validation fold for a single combination of the parameters you specify in the tuned_params. Based on best_score_, we can choose the ... 0 Your error is that you train your model to work on the training data after a scaling operation that you defined (fit) on the training. But then to evaluate using your test data you refit the scaler on the test data, meaning you are going to apply a different scaling to the test set, than you did on the training data to train the model. You need to not refit ... 1 My guess is you're not doing anything wrong. The algorithm depends on a random starting point, so two runs of the same algorithm will produce different results, unless you fix the seed of the random number generator. In this case you're comparing two different implementations, so who knows... Neither of the results has any clear structure that the other is ... 0 Your manual approach gives the MAE on the test set. Because you've set an integer for the parameter cv, the GridSearchCV is doing k-fold cross-validation (see the parameter description in grid search docs), and so the score .best_score_ is the average MAE on the multiple test folds. If you really want a single train/test split, you can do that in ... 1 I think that there are several problems, it's a bit difficult to disentangle them. Here are a few observations: First since you want to select the hyper-parameter$k$based on the data, you should use a separate validation set. This is because selecting$k\$ is akin to training, so currently you're using the test set both for training and testing. The proper ...