Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
9 views
2 pages
Slip Regression Classification
Uploaded by
prime04072001
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download
Save
Save slip_regression_classification For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
9 views
2 pages
Slip Regression Classification
Uploaded by
prime04072001
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save slip_regression_classification For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save slip_regression_classification For Later
You are on page 1
/ 2
Search
Fullscreen
import pandas as pd import numpy as np
from sklearn.model_selection import train_test_split #Clacification #DecisionTree
import statsmodels.api as sm from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import r2_score, mean_squared_error data = pd.get_dummies(data, columns=['famhist']) #no drop first
# Linear Regression model1 = DecisionTreeClassifier(criterion='gini', max_depth=6,
X = sm.add_constant(X) random_state=42) #gini
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, model3 = DecisionTreeClassifier(criterion='entropy', max_depth=6,
random_state=42) random_state=42) #info gain
reg = sm.OLS(y_train, X_train).fit() #reg.summary() model1.fit(X_train, y_train)
y_pred = reg.predict(X_test)
params = reg.params from sklearn.tree import plot_tree
p_val = reg.pvalues[1] plot_tree(model1, feature_names=list(X_features.columns),
print(f"Coefficients: b0: {params['const']}, b1: {params['Salary']}") class_names=["No CHD", "CHD"], filled=True, rounded=True)
print(r2_score(y_test, y_pred))
print(mean_squared_error(y_test, y_pred)) #KNN
from sklearn.neighbors import KNeighborsClassifier
residuals = reg.resid from sklearn.utils import resample, shuffle
std_residuals = reg.get_influence().resid_studentized_internal upsampled_not_joined = resample(not_joined, replace = True,
n_samples = 4000)
influence = reg.get_influence() dfs = [joined, upsampled_not_joined]
cook_distance = influence.cooks_distance[0] #plt.stem() new_df = pd.concat(dfs)
leverage = influence.hat_matrix_diag new_df = shuffle(new_df)
leverage_threshold = 3 * (len(X_train.columns) + 1) / len(X_train)
#cooks_threshold = 1 X = pd.get_dummies(X_features, drop_first=True)
#cook_outliers = np.where(cook_distance > cooks_threshold)[0] Y = new_df.Status.map(lambda x: int(x == 'Joined'))
train_X, test_X, train_Y, test_Y = train_test_split(X,Y,train_size=0.8,
#MLR random_state=42)
from statsmodels.stats.outliers_influence knn_clf = KNeighborsClassifier()
import variance_inflation_factor knn_clf.fit( train_X, train_Y )
def get_vif_factors(input_df) :
vif = pd.DataFrame() from sklearn.model_selection import GridSearchCV
vif["Features"] = input_df.columns tuned_parameters = [{ 'n_neighbors': range(5,10),'metric': ['canberra',
vif["VIF"] = [variance_inflation_factor(input_df.values, i) for i in 'euclidean','minkowski']}]
range(input_df.shape[1])] clf = GridSearchCV(
return vif KNeighborsClassifier(),tuned_parameters,cv=10,scoring='roc_auc')
clf.fit(train_X, train_Y)
#Residual plot between standardized model.fittedvalues and standardized print("Best score for KNN is : ",clf.best_score_)
model.resid print("Best parameter for KNN is : ", clf.best_params_)
#get_standardized_values = lambda x : (x - np.mean(x))/(np.std(x))
#Logistic Regression #ensemble
X = pd.get_dummies(X_features, drop_first=True) from sklearn.ensemble import RandomForestClassifier
X = sm.add_constant(X) radm_clf = RandomForestClassifier(max_depth=10, n_estimators=10)
model_1 = sm.Logit(train_Y, train_X).fit() radm_clf.fit( train_X, train_Y )
significant_features = model_1.pvalues[model_1.pvalues < 0.05].index
#make model with significant features from sklearn.ensemble import AdaBoostClassifier
from sklearn.linear_model import LogisticRegression
from sklearn import metrics logreg_clf = LogisticRegression()
cutoff = np.arange(0.1, 0.91, 0.01) ada_clf = AdaBoostClassifier(logreg_clf, n_estimators=50)
youdens_index = [] ada_clf.fit(train_X, train_Y)
cutoff_index = []
for i in cutoff: #SVM
predicted_values = model_2.predict(test_X) from sklearn.svm import SVC
predicted_values = (predicted_values > i).astype(int) svm_clf = SVC(kernel='linear', C=1.0, probability=True)
confusion_matrix = metrics.confusion_matrix(test_Y, predicted_values) svm_clf_poly = SVC(kernel='poly', degree=3, probability=True)
sensitivity = confusion_matrix[1][1]/(confusion_matrix[1][1] + svm_clf_rbf = SVC(kernel='rbf', gamma=0.1, probability=True)
confusion_matrix[1][0]) svm_clf_sigmoid = SVC(kernel='sigmoid', gamma='scale', coef0=0.0,
specificity = confusion_matrix[0][0]/(confusion_matrix[0][0] + probability=True)
confusion_matrix[0][1]) svm_clf.fit(train_X, train_Y)
youden_index = sensitivity + specificity - 1
youdens_index.append(youden_index)
cutoff_index.append(i)
print("Youden index : ", youdens_index)
max_youden = -40
optimal_cutoff = -1
for i in range(0, len(youdens_index)):
if(youdens_index[i] > max_youden) :
max_youden = youdens_index[i]
optimal_cutoff = cutoff_index[i]
#print( metrics.classification_report( test_Y, predicted_values ) )
'''For cost based cost = 5*confusion_matrix[0][1] + confusion_matrix[1][0]
and then find min instead of max like in youden'''
You might also like
Paired T and F Tests Student Template
PDF
No ratings yet
Paired T and F Tests Student Template
24,399 pages
Grade I A B
PDF
No ratings yet
Grade I A B
18,726 pages
Praksa
PDF
No ratings yet
Praksa
32,767 pages
Expresiones Algebraicas
PDF
No ratings yet
Expresiones Algebraicas
10,928 pages
SE184915 NguyenHoangThanhPhong Lab2
PDF
No ratings yet
SE184915 NguyenHoangThanhPhong Lab2
4,100 pages
ISO 230-2-2006-03 Test Code For Machine Tools-Part 2 Determination of Accuracy and Repeatability of Positioning Numerically Controlled Axes
PDF
100% (1)
ISO 230-2-2006-03 Test Code For Machine Tools-Part 2 Determination of Accuracy and Repeatability of Positioning Numerically Controlled Axes
39 pages
Vermilion Data
PDF
No ratings yet
Vermilion Data
40,458 pages
Line
PDF
No ratings yet
Line
71 pages
PKCL
PDF
No ratings yet
PKCL
32,767 pages
Dokument Akreditasi 2012
PDF
No ratings yet
Dokument Akreditasi 2012
32,767 pages
StatsAssign Data
PDF
No ratings yet
StatsAssign Data
1,639 pages
Week 6 Recitation Assignment
PDF
No ratings yet
Week 6 Recitation Assignment
32,767 pages
Panasonic+TC 32A400B+Fonte+TNP4G572+
PDF
100% (8)
Panasonic+TC 32A400B+Fonte+TNP4G572+
3 pages
Gauss Jordan - Matriz Inversa - Ramos Jimena
PDF
No ratings yet
Gauss Jordan - Matriz Inversa - Ramos Jimena
2,728 pages
SDFGXHCKL
PDF
No ratings yet
SDFGXHCKL
34,725 pages
Multidimensional Integration: 2.1 Line Integrals
PDF
No ratings yet
Multidimensional Integration: 2.1 Line Integrals
37 pages
Project GNCD
PDF
No ratings yet
Project GNCD
200 pages
07.01.25 Phy Annexure-Practicals
PDF
No ratings yet
07.01.25 Phy Annexure-Practicals
2,936 pages
Process Capability3
PDF
No ratings yet
Process Capability3
4,450 pages
Levene S Test
PDF
No ratings yet
Levene S Test
42 pages
2019 【CMC】 Contrastive Multiview Coding【多视角下的对比学习】
PDF
No ratings yet
2019 【CMC】 Contrastive Multiview Coding【多视角下的对比学习】
16 pages
Test Bank For Financial Accounting 12th
PDF
0% (2)
Test Bank For Financial Accounting 12th
813 pages
DM Cl2a
PDF
No ratings yet
DM Cl2a
34 pages
Akram Mohammed 1121
PDF
No ratings yet
Akram Mohammed 1121
1,642 pages
SPC Format
PDF
No ratings yet
SPC Format
61 pages
TKT2 1
PDF
No ratings yet
TKT2 1
108 pages
(Anup Sir) "Vector Analysis " by Abinash (AE-49)
PDF
No ratings yet
(Anup Sir) "Vector Analysis " by Abinash (AE-49)
37 pages
SK Finance 19-12-2024
PDF
No ratings yet
SK Finance 19-12-2024
37 pages
(Anup Sir) "Vector Analysis " by Abinash (AE-49)
PDF
No ratings yet
(Anup Sir) "Vector Analysis " by Abinash (AE-49)
37 pages
08 - Conjugate Duality
PDF
No ratings yet
08 - Conjugate Duality
15 pages
Slip
PDF
No ratings yet
Slip
2 pages
Ejercicio de Control P
PDF
No ratings yet
Ejercicio de Control P
24 pages
FLS Sales Data Without Adjustment
PDF
No ratings yet
FLS Sales Data Without Adjustment
24 pages
Wages Bill
PDF
No ratings yet
Wages Bill
35 pages
Zal 8 Plan Zagospodarowania Terenu Appx 8 Site Development Plan EN 21-12-2023 11.55.18 29-12-2023 15.47.09
PDF
No ratings yet
Zal 8 Plan Zagospodarowania Terenu Appx 8 Site Development Plan EN 21-12-2023 11.55.18 29-12-2023 15.47.09
1 page
Decision Tree
PDF
No ratings yet
Decision Tree
1 page
Logical Question Paper
PDF
No ratings yet
Logical Question Paper
2 pages
SECTOR 52 (Update 25.04.2023 Model - Mohit Attrish
PDF
No ratings yet
SECTOR 52 (Update 25.04.2023 Model - Mohit Attrish
1 page
Wavefit: An Iterative and Non-Autoregressive Neural Vocoder Based On Fixed-Point Iteration
PDF
No ratings yet
Wavefit: An Iterative and Non-Autoregressive Neural Vocoder Based On Fixed-Point Iteration
8 pages
Worksheet 1 Ch5
PDF
No ratings yet
Worksheet 1 Ch5
4 pages
Unit - 1
PDF
No ratings yet
Unit - 1
87 pages
Group Data: Levene's Test # of Groups ( 6)
PDF
No ratings yet
Group Data: Levene's Test # of Groups ( 6)
40 pages
Human Consciousness
PDF
No ratings yet
Human Consciousness
6 pages
Design and Manufacturing of Crankshaft by 3D Printing Technology
PDF
100% (1)
Design and Manufacturing of Crankshaft by 3D Printing Technology
12 pages
Group Data: Levene's Test # of Groups ( 6)
PDF
No ratings yet
Group Data: Levene's Test # of Groups ( 6)
40 pages
06 - Optimality Conditions
PDF
No ratings yet
06 - Optimality Conditions
8 pages
Clustering Part2 Continued: Han/Eick: Clustering II 1
PDF
No ratings yet
Clustering Part2 Continued: Han/Eick: Clustering II 1
33 pages
5 Axis Generic Post
PDF
82% (11)
5 Axis Generic Post
68 pages
FLS Sales Data Without Adjustment
PDF
No ratings yet
FLS Sales Data Without Adjustment
8 pages
Python-Control Cheat Sheet
PDF
No ratings yet
Python-Control Cheat Sheet
1 page
Theory of Elasticity - Timoshenko
PDF
17% (6)
Theory of Elasticity - Timoshenko
368 pages
Vlookup Lesson 1
PDF
No ratings yet
Vlookup Lesson 1
38 pages
123 Easy Essay
PDF
100% (2)
123 Easy Essay
4 pages
In Certi Dumb Ree
PDF
No ratings yet
In Certi Dumb Ree
28 pages
Excel 1
PDF
No ratings yet
Excel 1
27 pages
Design of Common Raft: Loads On Column at Base
PDF
No ratings yet
Design of Common Raft: Loads On Column at Base
20 pages
Input INV
PDF
No ratings yet
Input INV
1 page
Game Theory - The Chicken Game
PDF
No ratings yet
Game Theory - The Chicken Game
9 pages
COMP7015 Assignment 4 Sample Solutions
PDF
No ratings yet
COMP7015 Assignment 4 Sample Solutions
4 pages
The Effects of Classroom Environment in Engagement and Academic Performance of Grade 12 Abm Students at Notre Dame of Trece MARTIREZ S.Y. 2023-2024
PDF
No ratings yet
The Effects of Classroom Environment in Engagement and Academic Performance of Grade 12 Abm Students at Notre Dame of Trece MARTIREZ S.Y. 2023-2024
25 pages
Surya (Sun) : Page - 1
PDF
100% (1)
Surya (Sun) : Page - 1
13 pages
Quantitative Reliability Evaluation
PDF
No ratings yet
Quantitative Reliability Evaluation
8 pages
Can Be Has: M/2019/01/02/hash-Match - Join - Internals
PDF
No ratings yet
Can Be Has: M/2019/01/02/hash-Match - Join - Internals
1 page
MATH 3131 Sept 13, 2013 Assignment 1
PDF
No ratings yet
MATH 3131 Sept 13, 2013 Assignment 1
4 pages
Action Guide
PDF
No ratings yet
Action Guide
48 pages
Atomic Doctors
PDF
No ratings yet
Atomic Doctors
313 pages
Simulation Project I Beam 1000kg Load
PDF
No ratings yet
Simulation Project I Beam 1000kg Load
10 pages
Syllabus Viii Mid Term 2025
PDF
No ratings yet
Syllabus Viii Mid Term 2025
2 pages
Mindscapes Class 6 To 8
PDF
No ratings yet
Mindscapes Class 6 To 8
27 pages
Spillway
PDF
No ratings yet
Spillway
39 pages
Managing Your Emotions at Work
PDF
No ratings yet
Managing Your Emotions at Work
22 pages
Ai and You Slide Template
PDF
No ratings yet
Ai and You Slide Template
30 pages
Generating The General Linear Group of Degree Two
PDF
No ratings yet
Generating The General Linear Group of Degree Two
15 pages
1.EFP - 100AF - 110 - 2 - E 1000 USGPM@99m
PDF
No ratings yet
1.EFP - 100AF - 110 - 2 - E 1000 USGPM@99m
3 pages
Soal Reference Types Questions
PDF
No ratings yet
Soal Reference Types Questions
10 pages
Assignment Stress Strain Diagram
PDF
No ratings yet
Assignment Stress Strain Diagram
26 pages
Speaking Hawai
PDF
No ratings yet
Speaking Hawai
11 pages
Subject Index - 2017 - Introduction To Optimum Design Fourth Edition
PDF
No ratings yet
Subject Index - 2017 - Introduction To Optimum Design Fourth Edition
17 pages
Hhe QC WP 016
PDF
No ratings yet
Hhe QC WP 016
8 pages
Yearly Scheme of Work Year 1
PDF
No ratings yet
Yearly Scheme of Work Year 1
10 pages
1689580033sarkarinaukriexams com-TCS NQT Syllabus 2023 Exam Pattern PDF Download
PDF
No ratings yet
1689580033sarkarinaukriexams com-TCS NQT Syllabus 2023 Exam Pattern PDF Download
6 pages
Tutorial 5
PDF
No ratings yet
Tutorial 5
12 pages
For FRP Abaqus
PDF
No ratings yet
For FRP Abaqus
7 pages
Application of Cutting Stock Problem in
PDF
No ratings yet
Application of Cutting Stock Problem in
6 pages
Introduction To Robots
PDF
No ratings yet
Introduction To Robots
2 pages
5.1 5. (Textbook) Abstract Nouns PDF
PDF
No ratings yet
5.1 5. (Textbook) Abstract Nouns PDF
4 pages
Brochure - Fibra-Cel Disks Questions and Answers
PDF
No ratings yet
Brochure - Fibra-Cel Disks Questions and Answers
4 pages
C Programming
From Everand
C Programming
Netra
No ratings yet
Computer Engineering Laboratory Solution Primer
From Everand
Computer Engineering Laboratory Solution Primer
Karan Bhandari
No ratings yet
Amazing Java: Learn Java Quickly
From Everand
Amazing Java: Learn Java Quickly
Andrei Besedin
No ratings yet
Documents
Teaching Methods & Materials
Mathematics