r/scikit_learn • u/[deleted] • May 04 '20
Code a Decision Tree in 20 lines.
r/scikit_learn • u/bazziapps • Jun 24 '20
r/scikit_learn • u/khalkhall • Jun 17 '20
I have this assignment for a job interview and I really want to impress by using some machine learning. I don't know too much about it and I essentially don't have much time to learn that much about it. I have the following dataframe and I want to create a linear regression using scikitlearn of ['profit'] vs ['dateReceived'] for each ['Language'].
Does anyone know what I can do for that to work? I guess it should be just a few lines of code, but I could be wrong?
r/scikit_learn • u/jac5423 • Jun 25 '21
I am learning logistic regression on python but I am very confused on what x_train/test and y_train/test does. What do the test and train mean and do and what are the x and y?
Also, what is the point of splitting data?
r/scikit_learn • u/AromaticCustomer7765 • Feb 21 '21
I'm new to scikit-learn. I made a dataset of 5 points. so I want to use PolynomialFeatures to fit a single curve but it gives me multiple curves. can you help me with this?
Here is my code:
import numpy as np
import matplotlib. pyplot as plt
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
x=np.random.normal(size=5)
y= 2.2 * x - 1.1
y= y + np.random.normal(scale=3, size=y.shape)
x=x.reshape(-1,1)
preproc=PolynomialFeatures(degree=4)
x_poly=preproc.fit_transform(x)
x_line=np.linspace(-2,2,100)
x_line=x_line.reshape(-1,1)
poly_line=PolynomialFeatures(degree=4)
y_line=poly_line.fit_transform(x_line)
plt.plot(x,y,"bo")
plt.plot(x_line,y_line,"r.")
I want a single fit curve but it gives me multiple fit curves. can anybody help me with this?

r/scikit_learn • u/joanna58 • Jul 21 '22
r/scikit_learn • u/Alphac3ll • Aug 09 '23
Hello,
I have a project where I need to recognize car models , in my case I need to differentiate 8 of them. I was trying to make the AI model with tensorflow previously but the run times are horrible and the best accuracy I could get is 85%, I was wondering if using scikit could maybe speed the process up and get a better result? Currently I have 8 categories (8 different cars) and each has 500 images so roughly 4000 images total for processing. I've just heard about scikit on my job and heard good stuff about it too. Any input on this is welcome :D . Thanks in advance
r/scikit_learn • u/microsat2 • Mar 29 '23
The following code is extracted from https://scikit-learn.org/stable/modules/model_evaluation.html#scoring-parameter
But it cannot be run correctly. Please help fix it.
from sklearn.model_selection import cross_validate
from sklearn.metrics import confusion_matrix
from sklearn.svm import LinearSVC
# A sample toy binary classification dataset
X, y = datasets.make_classification(n_classes=2, random_state=0)
svm = LinearSVC(random_state=0)
def confusion_matrix_scorer(clf, X, y):
y_pred = clf.predict(X)
cm = confusion_matrix(y, y_pred)
return {'tn': cm[0, 0], 'fp': cm[0, 1],'fn': cm[1, 0], 'tp': cm[1, 1]}
cv_results = cross_validate(svm, X, y, cv=5, scoring=confusion_matrix_scorer)r/scikit_learn • u/PengyDesu • Oct 11 '20
I am currently working on a beginner project on logistic regression using scikit_learn. I am trying to fine tune my regression model but cant seem to find any websites that can explain what the parameters mentioned in the title mean exactly and how to use them. I was wondering if anyone could give me a quick explanation on what/how to use these parameters to fine tune my regression model.
r/scikit_learn • u/[deleted] • Nov 26 '18
Does cross_val_score tell something about generalizability?
Or do I need to use something else for measuring generalizability?
r/scikit_learn • u/chop_hop_tEh_barrel • Aug 26 '20
I'm using scikit learn for linear regression. Is there a way to use that library to generate things like T-Stastic and p-value and standard error etc?
On stack overflow i found this, but wondering if there's a way within scikit
import statsmodels.api as sm
from scipy import stats
X2 = sm.add_constant(X)
est = sm.OLS(y, X2)
est2 = est.fit()
print(est2.summary())r/scikit_learn • u/Hussain_Mujtaba • Jul 29 '20
r/scikit_learn • u/[deleted] • Nov 19 '18
Does sklearn have built-in routines for testing results of LinearRegression()?
r/scikit_learn • u/m3her_ • May 02 '21
r/scikit_learn • u/tusharkulkarni95 • Apr 01 '20
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('50_Startups.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 4].values
X2=dataset.iloc[:, 3].values
# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
le = LabelEncoder()
X2 = le.fit_transform(X2)
oh = OneHotEncoder(categories = 'X[:, 3]')
X= oh.fit_transform(X).toarray()

r/scikit_learn • u/koderjim • Apr 28 '22
r/scikit_learn • u/Old-Bike-8739 • May 21 '24
Miért viselkednek a beteggel úgy ahogy? Valamelyik reggel rosszul lettem. Szédültem,nyomott a mellkasom és száradtam mentő pedig nem akart kijönni! Be mentem a sürgőségire, ahol úgy beszéltek velem mind 1 kutyával. Sőt az ember a kutyájával szebben beszél. Le vették a vért és közöltem, hogy rosszul vagyok a vérvételtől. Átvéreztem azután szóltam ,hogy le cseréli-e vagy valami,mert világos felső volt rajtam és küldött ki , hogy kint várjam meg az eredményt. Erre idegesen közölte velem, hogy old meg magadnak, mit csináljak én veled? Megjött az eredmény be mentem. Ajtót nekem vágta, ahogy nyitotta ki és morgott , hogy minek állok ott. Nem találtak semmit de , hogy ők mit csináljanak vele. Illedelmesen alá írtam és közöltem velük, hogy beszélhetnének szebben is a betegekkel és el köszöntem.
r/scikit_learn • u/Carl_felix • Mar 13 '21
Hi everybody,
I'm testing the performance of scikitlearn KNN, I'm using a dataset with 30 features and 284807 lines. I splitted it in 0,8 for training and 0,2 for test, it means I'm using 56962 rows for the validation.
What I don't understand is that when I use the prediction only in one row the time to do the calculation is:
time: 7.773932695388794 s
and when I do for all the 56962 rows, the scikitlearn can proccess it in almost the same period of time:
time: 12.312492370605469 s
I can't understand how scikitlearn do it? It runs some kind of parallelization(I don't think so)? What kind of optimization it uses? Because if I use a "loop" to iterate through all the rows it would take a long long long time to do all the predictions.
The code:
import time
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
df = pd.read_csv('creditcard.csv')
X = df.drop(columns=['Class'])
y = df['Class']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1, stratify=y)
X_test_one = X_test.iloc[[0]]
#Running one row
t1 = time.time()
knn = KNeighborsClassifier(n_neighbors = 3)
knn.fit(X_train,y_train)
print(knn.predict(X_test_one))
t2 = time.time()
print("time: " + str(t2-t1))
#Running all the rows
t3 = time.time()
knn = KNeighborsClassifier(n_neighbors = 3)
knn.fit(X_train,y_train)
print(knn.predict(X_test))
t4 = time.time()
print("time: " + str(t4-t3))
r/scikit_learn • u/Ashraf_mahdy • Aug 20 '23
I am doing a Masters in Construction and Real Estate Management. My topic is about scheduling using historical data. I learned most of my knowledge through Code Academy and I am now in the process of writing my model and debugging it on a sample dataset I created myself.
The problem I am facing when running it is that the model parameters apparently don't lead to convergence. or perhaps I am choosing wrong models to process my data idk
I use Spyder's Python IDE in Anaconda Desktop A few things to note:
I am trying to utilize pipelines for data preprocessing
I am trying to use pipelines to iterate over a selection of models and boosting techniques and Hyperparameters to come up with the best model for my data, this is where I think the issue is mostly
PLEASE MESSAGE ME IF YOU CAN HELP! I PROMISE THE AMOUNT OF HELP IS NOT BIG
r/scikit_learn • u/[deleted] • Nov 11 '20
Hi, I'm doing Logistic regression with sklearn and I am using the train test split. No matter which tesz_size I pass, I always get around 80% on my score. Am I doing something wrong?
r/scikit_learn • u/qudcjf7928 • May 04 '20
all of my input features are positive. Whenever I tried to apply PowerTransformer with box-cox method, the lambdas are s.t. the transformed values have zero variance. i.e. the features become constants
I even tried with randomly generated log normal data and it still transform the data into zero variance.
I do understand that mathematically, finding the lambda s.t. the standard deviation is the smallest, would mean the distribution would be the most normal-like.
But when the standard deviation is zero, then what's the point of using it?
p.s. so one of the values of lambda I get by using PowerTranformer is -4.78
If you apply it into the box-cox equation for lambda != 0.0, then for any input feature y values, you technically get the same values. i.e. (100^(-4.78)-1.0)/(-4.78) is technically equals to (500^(-4.78)-1.0)/(-4.78)
r/scikit_learn • u/catanicbm • Dec 31 '22
r/scikit_learn • u/zippercomics • Jan 17 '22
Hi all,
I'm trying to pick up the rudiments of SciKit. I'm very new to this, so I apologize if this is an obvious or dumb question ... I'm looking at the DecisionTreeClassifier.fit method, and I see it needs an input and output method. In the example I see, there's two input columns and a third output column. Easy enough.
The thing is, the fit method imports the input (which is the first two), and the output (which is the third column). When the predict method is run ... how does the model know which inputs are matched to which outputs? Am I thinking of this too "old school", in that these aren't actually two separate data sets, but instead are just pointers to the holistic data set?
I feel like the answer is that it's still referring to the original dataset, and that the input and output are basically just qualifiers that tell the prediction model which columns to use. But I'd feel better if I knew that were the case, or if I'm way off and there's something else happening.
As always, I appreciate any help, and I hope this question makes sense.
Thanks!