Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dsai-challenge-solution
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mychajlo Chodorev
dsai-challenge-solution
Commits
d8c3a408
Commit
d8c3a408
authored
5 years ago
by
Mychajlo Chodorev
Browse files
Options
Downloads
Patches
Plain Diff
SVC
parent
e12f9012
No related branches found
Branches containing commit
Tags
submission-10
submission-9
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
model_builder.py
+46
-0
46 additions, 0 deletions
model_builder.py
with
46 additions
and
0 deletions
model_builder.py
0 → 100644
+
46
−
0
View file @
d8c3a408
import
numpy
as
np
import
pandas
as
pd
from
sklearn
import
metrics
from
sklearn
import
preprocessing
from
sklearn
import
svm
#from sklearn.linear_model import LogisticRegression
from
sklearn.model_selection
import
train_test_split
#from sklearn.naive_bayes import BernoulliNB
from
progressbar
import
progressbar
import
joblib
def
get_model
():
print
(
"
Reading data...
"
)
df_data
=
pd
.
read_csv
(
'
data/data_cleansed.csv
'
).
drop
(
columns
=
[
'
Unnamed: 0
'
,
'
Unnamed: 0.1
'
,
'
data_type
'
])
selected_features
=
pd
.
read_csv
(
'
data/selected_features.csv
'
).
iloc
[:,
0
]
#df_data = df_data.set_index("intClinicalTrialID")
#df_data = df_data.join(pd.DataFrame(columns = selected_features), rsuffix = '_right')
y
=
df_data
[
'
approved
'
]
df_data
=
df_data
[
selected_features
]
print
(
"
Normalizing data...
"
)
X
=
preprocessing
.
StandardScaler
().
fit
(
df_data
).
transform
(
df_data
.
astype
(
float
))
print
(
"
Creating train and test sets...
"
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.3
,
random_state
=
4
)
# BernoulliNB
# print("Training BernoulliNB model...")
# nb = BernoulliNB().fit(X_train, y_train)
# y_hat = nb.predict(X_test)
# print("Accuracy: {}".format(metrics.accuracy_score(y_test, y_hat)))
# SVM
print
(
"
Training SVM...
"
)
svc_rbf
=
svm
.
SVC
(
kernel
=
'
rbf
'
,
C
=
100
,
probability
=
True
).
fit
(
X_train
,
y_train
)
#print("RBF accuracy: {}".format(metrics.accuracy_score(y_test, svc_rbf.predict(X_test))))
return
svc_rbf
#Logistic regression
#lr = LogisticRegression(C = 0.01).fit(X_train, y_train)
#print("Logistic regression accuracy: {}".format(metrics.accuracy_score(y_test, lr.predict(X_test))))
if
__name__
==
"
__main__
"
:
joblib
.
dump
(
get_model
(),
'
data/model.svc
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment