Posts

Showing posts with the label scikit-learn

Sklearn : Get last split from timeSeriesSplit

Sklearn : Get last split from timeSeriesSplit So I am using the timeSeriesSplit from sklearn to split my data like this, tscv = TimeSeriesSplit(n_splits=3) Now I know in order to get the split indices we have to iterate over tscv.split(X) . My question here is, is it possible to get directly to the last split, without iterating over the splits. The object returned by the function is not exactly a list, so I am not sure how to do this ? I need the last split only, since my data is large and no. of splits is also large. tscv.split(X) Thanks in advance 2 Answers 2 You can try this def get_last_cv(splits): splits_deque = deque(splits, maxlen=1) last_element = splits_deque.pop() train,test = last_element return train,test and then get the indices like this train_index,test_index = get_last_cv(tscv.split(X)) where X is your data X Split method in TimeSeriesSplit generates split of indi...

Making Quantile Regression Example work for my own dataset in sklearn

Making Quantile Regression Example work for my own dataset in sklearn I am trying to implement quantile regression for my problem using the code at http://scikit-learn.org/stable/auto_examples/ensemble/plot_gradient_boosting_quantile.html I want to use the exact same code for my model. I am mainly interested in the quantile part. My data is simple, I have a bunch of features, a 5 dimensional vector as my input and a real value as y. So, instead of the data (x, sin(x)) in the above code, I am trying to get the model work for my own (X, y). The problem is, they are using xx as separate variables in the code, if I set xx to X, the code just gets messed up with a useless noisy visualisation. I described the specific changes I made, hoping the model to work, I tried a few other things as well to retrofit my data to the model. How should the code be modified to work on my inputs. What specific changes should be made? By cli...

Scikit-learn: Less points plotted than initial data samples after clustering with DBSCAN

Scikit-learn: Less points plotted than initial data samples after clustering with DBSCAN I was using the DBSCAN implementation from the library scikit-learn, when I discovered that the number of points plotted was inferior to the number of initial samples. In particular, in the official demo of DBSCAN http://scikit-learn.org/stable/auto_examples/cluster/plot_dbscan.html, 750 samples are generated automatically. However, when I print how many points there are for each cluster and how many outliers, the result is: CLUSTER 1: 224, CLUSTER 2: 228, CLUSTER 3: 227, OUTLIERS : 18, --> TOTAL = 697. As you can see from the following code, I have just added few lines to the original code, to print for each cluster the number of points and the number of outliers. I am confused about this and I would like to know why this happens and where are the missing points. Thanks in advance for the answers! print(__doc__) import numpy as np from sklearn.cluster import DBSCAN from sklearn import metrics f...