-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Assignment1 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import pandas as pd | ||
| import plotly.express as px | ||
| from sklearn.ensemble import RandomForestClassifier | ||
| from sklearn.linear_model import LogisticRegression | ||
| from sklearn.metrics import classification_report, confusion_matrix | ||
| from sklearn.model_selection import train_test_split | ||
| from sklearn.preprocessing import StandardScaler | ||
| from sklearn.svm import SVC | ||
| from sklearn.pipeline import Pipeline | ||
|
|
||
| #Loading data into Pandas | ||
| df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', | ||
| names=["SepalLengthCm", "SepalWidthCm", "PetalLengthCm", "PetalWidthCm", "Species"]) | ||
| print(df) | ||
|
|
||
| #Summarizing stats | ||
| print(df.describe()) | ||
|
|
||
|
|
||
| #Some Random Figures | ||
| fig = px.scatter(df, x="SepalWidthCm", y="SepalLengthCm", color="Species", size='PetalLengthCm', | ||
| hover_data=['PetalWidthCm']) | ||
| #fig.show() | ||
|
|
||
| fig2 = px.bar(df, x="SepalWidthCm", y="SepalLengthCm", color="Species") | ||
| #fig2.show() | ||
|
|
||
| fig3 = px.box(df, y="PetalWidthCm", color="Species", points='all') | ||
| #fig3.show() | ||
|
|
||
| fig4 = px.violin(df, y="PetalLengthCm", color="Species", violinmode='overlay', hover_data=df.columns) | ||
| #fig4.show() | ||
|
|
||
| fig5 = px.ecdf(df, x="SepalLengthCm", y="SepalWidthCm", color="Species", ecdfnorm=None) | ||
| #fig5.show() | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do fig1.show(),fig2.show(), etc so we can see the plots. the code runs fine but they don't show up unless you have them
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the note! I commented fig.show() to the code. |
||
| #we can tell Setosa tend to have larger sepal width, while versicolor and virginica have larger sepal length | ||
|
|
||
| #Train and Test Datasets | ||
| X = df.drop('Species', axis=1) | ||
| y = df['Species'] | ||
|
|
||
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20) | ||
| print(X_train) | ||
|
|
||
| scale = StandardScaler() | ||
| scale.fit(X_train) | ||
| X_train_sc = scale.transform(X_train) | ||
| X_test_sc = scale.transform(X_test) | ||
|
|
||
| #Random Forest | ||
| clf = RandomForestClassifier(n_estimators=100) | ||
| clf.fit(X_train_sc, y_train) | ||
| predictor = clf.predict(X_test_sc) | ||
|
|
||
| pipeline = Pipeline([('scaler', StandardScaler()), ('classifier', RandomForestClassifier())]) | ||
| pipeline.fit(X_train_sc, y_train) | ||
| r2 = pipeline.score(X_test_sc, y_test) | ||
| print(f"RFR: {r2}") | ||
|
|
||
| #Other models - SVC and Logistic Regression | ||
| svclassifier = SVC(kernel='poly', degree=8) | ||
| svclassifier.fit(X_train_sc, y_train) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again the code runs fine here and everything ran right, but print out the values you get from the classifier.fit so we can see if the models are accurate or not
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well the code includes confusion matrix for both models which shows accuracy, precision, recall and F1 score. |
||
| predictor_svc = svclassifier.predict(X_test_sc) | ||
|
|
||
| print(confusion_matrix(y_test, predictor_svc)) | ||
| print(classification_report(y_test, predictor_svc)) | ||
|
|
||
| logreg = LogisticRegression() | ||
| logreg.fit(X_train_sc, y_train) | ||
| predictor_reg = logreg.predict(X_test_sc) | ||
|
|
||
| print(confusion_matrix(y_test, predictor_reg)) | ||
| print(classification_report(y_test, predictor_reg)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,26 @@ | ||
| numpy | ||
| fastapi | ||
| flake8==5.0.4 | ||
| flask | ||
| graphviz | ||
| gunicorn | ||
| isort[requirements] | ||
| netcal | ||
| nose | ||
| numpy | ||
| pandas | ||
| pip-tools | ||
| pre-commit | ||
| plotly | ||
| pydot | ||
| pygam | ||
| pyspark | ||
| pyspark-stubs | ||
| requests | ||
| scikit-learn | ||
| seaborn | ||
| statsmodels | ||
| sqlalchemy | ||
| sympy | ||
| uvicorn | ||
| wheel | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.