7

This is an implementation detail, and I wouldn't necessarily rely on this behavior, but presently in sklearn, it will choose the "first" class. The predict method calls for the probability prediction, then takes the argmax, which in case of ties takes the first one: https://github.com/scikit-learn/scikit-learn/blob/fd237278e/sklearn/tree/_classes....


5

Apparently this functionality is left out intentionally, see here. I'm afraid you have to use SVD, but that should be fairly straightforward: def pca(X): mean = X.mean(axis=0) center = X - mean _, stds, pcs = np.linalg.svd(center/np.sqrt(X.shape[0])) return stds**2, pcs


4

No, extremely-random trees does still optimize splits. It does only pick one random splitting point for each feature (out of those randomly chosen max_features) but then which feature is actually used for the split depends on the criterion chosen. https://scikit-learn.org/stable/modules/ensemble.html#extremely-randomized-trees


4

In scikit-learn, most algorithms (SVM, Decision Trees, SGD, etc.) have a sample_weight argument that you can pass when fitting. In your case, you could provide a different weight based on which of the 3 datasets the data point comes from. If the algorithm you want to use doesn't provide the sample_weight argument, you can always sample with replacement. ...


3

which is good for production They are both good. sklearn can be used in production as much as tensorflow.keras which will give me better and faster response I think that doesn't really depends on the libray, rather on the size of your models and of your datasets. That what really matters. Both modules can be used to create very optimized and fast models. ...


3

What I would suggest is to build a sklearn pipeline in which one step will be the sklearn PCA and the last step will be your Keras model. Sklearn pipelines are easy to put into production and can handle a lot more of transformations.


2

One option is scikit-learn's ColumnTransformer applied to mixed types. ColumnTransformer is designed for the purpose of applying different preprocessing and feature extraction pipelines to different subsets of the features.


2

Is that intuition correct Yes There is no improvement in Cluster quality. All the 3 are the same and should be that way. We can easily observe that all the 3 clusters are forming the elbow at 2.5. Even all other aspects of the 3 plots are exactly the same. Within Cluster Sum of Squares (WCSS) measures the squared average distance of all the points within a ...


2

Welcome to the community! Some points which might help: Clustering, as an unsupervised task, can not be evaluated and usually some external criteria are used to find the best clustering. According to the point above, better to make those assumptions as direct as possible. Starting with EDA (inspecting histograms, plotting boxplots, etc.) gives you a better ...


2

threshold_90_precision = thresholds[np.argmax(precisions >= 0.9)] Above snippet is not doing what you are expecting it to do. Try these changes precisions[precisions < 0.9] = 1 threshold_90_precision = thresholds[np.argmin(precisions)] Also, I am not sure whether you are calculating the accuracy properly since z_scores is decision function, not ...


2

Weka's decision trees are from the Quinlan family, whereas sklearn uses CART. The most notable difference is that Quinlan trees aren't restricted to binary splits: a categorical column will be split into subtrees for each level. Another is how missing values are dealt with, but there are some differences in individual implementations, so it's not ...


1

It appears to me that what you're looking for in your use-case is not clustering - it's a distance metric. When you get a new data point, you want to find the 3-5 most similar data points; there's no need for clustering for it. Calculate the distance from the new data point to each of the 'old' data points, and select the top 3-5. Now, which distance metric ...


1

Did you check tinynumpy? Anyway, I rarely found alternatives to famous packages (except scikit-image instead of opencv). What usually works for me is: Slim the model as much as I can (e.g. weights quantization) Check in the code which functions I use from each module. Once I have a list of them, I retrieve the corresponding python files and get rid of the ...


1

Indeed, they don't seem to be used for anything. Probably they were included for some initial debugging? An issue (and a linked PR) discussing these methods: https://github.com/scikit-learn/scikit-learn/issues/13330 (At time of posting,) searching for n_calls only finds results in _binary_tree.pxi, and none of them seem actually used for anything other than ...


1

I agree to opinions said before. Just as alternative, if you see that customer behavior is too different if it is a guest or not, depending also on model you use, probably it would make sense to use two different models. For example, if you know will use LogisticRegression and not regular customers behavior is distributed in bigger range, then probably you ...


1

Welcome to Data Science at StackExchange, One way to accomplish this is to use the stratify option in train_test_split, since you are already using that function (this will also work for ensuring your labels are equally distributed, very useful in modelling an unbalanced dataset): Train,Test = train_test_split(df, test_size=0.50, stratify=df['B']) In my ...


1

Most probably, sum across one of the rows is coming out as zero in this code matrix = matrix.astype('float') / matrix.sum(axis=1)[:, np.newaxis] It is throwing a runtime warning and only that particular cell will be np.inf. Rest all division will be fine. That's why the plot is showing some data. You may see the same in this sample code import numpy as np ...


1

In your plot you used PCA to reduce the dimensionality of your data, but you plotted the first 2 dimensions of your centroids. You should also transform the centroids using the PCA transform you fitted on your data. This code should work for you numClusters= 12 kmeans = KMeans(n_clusters=numClusters).fit(X) centroids = kmeans.cluster_centers_ # Predicting ...


1

Where are you evaluating the performance of your algorithm? Are you making a train test split and evaluating in the test split? It might be that you overfitted your train and you are just measuring the accuracy there. If you have made correctly the train/test split and the evaluation it could be that the images that you are predicting do not have the same ...


1

This is difficult to answer without more context of your exact scenario. Typically, though, it's not the best idea to add a large library into a project for just one piece of functionality - especially if it's as simple as PCA. PCA is fairly simple to implement, even with just NumPy, and you will probably be using NumPy if you're using Keras. However, as you ...


1

If you are looking for a statistical trick, I don't know, but Recently Andrew NG team recently published about NGBoost. NGBoost is a new boosting algorithm, which uses Natural Gradient Boosting, a modular boosting algorithm for probabilistic predictions. In this Towards Data Science toy example you can see how to use the Python API: Quoting the TDS author: ...


1

I had much better results with the decision forest. The diabetes pedigree function requires good diabetes diagnostic history of the persons relatives. Based on this, it might be neglectable.


1

The criterion parameter is used to measure the quality of the split when selected, it is not involved in the initial splitting algorithm (the features used for the split are chosen randomly) ExtraTreesRegressor: mse and mae are the only options available for use, and mse is the default. mae was added after version 0.18. Check your version if it is available....


1

get_support() will only return an array, there are no column names in that object. Check this website out for usage: https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectKBest.html In your code, mask will show an array of True or False values print(mask) [ True True True True False ... False] If you want the column names, ...


1

Accuracy is not the best measure for imbalanced data. Prefer precision and recall. Do undersampling/oversampling to get equal samples for each class and try XGBoost. Or else you can use SVC with class weights, give lower class weight to classes with more samples and vice versa.


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