MuzammilMax commited on
Commit
0615822
·
verified ·
1 Parent(s): 2406611

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -99
app.py CHANGED
@@ -225,7 +225,7 @@ def ode1(A0, B0, C0, temp, Ea, A_factor):
225
  results = []
226
 
227
  counter = 0
228
- while counter < 15000:
229
  counter += 1
230
 
231
  A0 = round(random.uniform(1.0, 10.0), 2)
@@ -272,7 +272,7 @@ df_train
272
  results = []
273
 
274
  counter = 0
275
- while counter < 5000:
276
  counter += 1
277
 
278
  A0 = round(random.uniform(1.0, 10.0), 2)
@@ -358,131 +358,131 @@ X_test_scaled = scaler.transform(X_test)
358
 
359
  """## Models"""
360
 
361
- from sklearn.metrics import accuracy_score
362
 
363
  """### Logistic Regression"""
364
 
365
- from sklearn.linear_model import LogisticRegression
366
 
367
- lr = LogisticRegression(max_iter=1000, C=10, penalty='l2')
368
- lr.fit(X_train_scaled, y_train)
369
- lr_pred = lr.predict(X_test_scaled)
370
 
371
- print("Logistic Regression Accuracy:", accuracy_score(y_test, lr_pred))
372
 
373
  """### RandomForestClassifier"""
374
 
375
- from sklearn.ensemble import RandomForestClassifier
376
 
377
- rf = RandomForestClassifier(class_weight='balanced', random_state=42, n_estimators=200, max_depth=None)
378
- rf.fit(X_train, y_train)
379
- rf_pred = rf.predict(X_test)
380
 
381
- print("RandomForestClassifier Accuracy:", accuracy_score(y_test, rf_pred))
382
 
383
  """### Gradient Boosting Classifier"""
384
 
385
- from sklearn.ensemble import GradientBoostingClassifier
386
 
387
- gb = GradientBoostingClassifier(n_estimators=200, max_depth=5, random_state=42)
388
- gb.fit(X_train, y_train)
389
- gb_pred = gb.predict(X_test)
390
 
391
- print("Gradient Boosting Accuracy:", accuracy_score(y_test, gb_pred))
392
 
393
  """### Support Vector Classifier"""
394
 
395
- from sklearn.svm import SVC
396
 
397
- svc = SVC(C=10, kernel='rbf', class_weight='balanced')
398
- svc.fit(X_train_scaled, y_train)
399
- svc_pred = svc.predict(X_test_scaled)
400
 
401
- print("SVC Accuracy:", accuracy_score(y_test, svc_pred))
402
 
403
  """### K-Nearest Neighbors"""
404
 
405
- from sklearn.neighbors import KNeighborsClassifier
406
 
407
- knn = KNeighborsClassifier(n_neighbors=7, weights='uniform')
408
- knn.fit(X_train_scaled, y_train)
409
- knn_pred = knn.predict(X_test_scaled)
410
 
411
- print("KNN Accuracy:", accuracy_score(y_test, knn_pred))
412
 
413
  """### XG Boost"""
414
 
415
- from xgboost import XGBClassifier
416
 
417
- xgb_model = XGBClassifier(learning_rate=0.1, max_depth=7, n_estimators=200, eval_metric='mlogloss', random_state=42)
418
- xgb_model.fit(X_train, y_train)
419
- xgb_pred = xgb_model.predict(X_test)
420
 
421
- print("XGBoost Accuracy:", accuracy_score(y_test, xgb_pred))
422
 
423
  """### Hyperparameter tuning"""
424
 
425
- from sklearn.linear_model import LogisticRegression
426
- from sklearn.svm import SVC
427
- from sklearn.neighbors import KNeighborsClassifier
428
- from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
429
- import xgboost as xgb
430
-
431
- models = {
432
- 'LogisticRegression': LogisticRegression(class_weight='balanced', max_iter=1000),
433
- 'SVC': SVC(class_weight='balanced'),
434
- 'KNN': KNeighborsClassifier(),
435
- 'RandomForest': RandomForestClassifier(class_weight='balanced', random_state=42),
436
- 'GradientBoosting': GradientBoostingClassifier(random_state=42),
437
- 'XGBoost': xgb.XGBClassifier(eval_metric='mlogloss', random_state=42)
438
- }
439
-
440
-
441
- param_grids = {
442
- 'LogisticRegression': {
443
- 'C': [0.1, 1, 10],
444
- 'penalty': ['l2']
445
- },
446
- 'SVC': {
447
- 'C': [0.1, 1, 10],
448
- 'kernel': ['linear', 'rbf']
449
- },
450
- 'KNN': {
451
- 'n_neighbors': [3, 5, 7],
452
- 'weights': ['uniform', 'distance']
453
- },
454
- 'RandomForest': {
455
- 'n_estimators': [100, 200],
456
- 'max_depth': [5, 10, None]
457
- },
458
- 'GradientBoosting': {
459
- 'n_estimators': [100, 200],
460
- 'max_depth': [3, 5, 7]
461
- },
462
- 'XGBoost': {
463
- 'n_estimators': [100, 200],
464
- 'max_depth': [3, 5, 7],
465
- 'learning_rate': [0.05, 0.1]
466
- }
467
- }
468
-
469
- from sklearn.model_selection import GridSearchCV
470
-
471
- best_models = {}
472
-
473
- for name, model in models.items():
474
- print(f"Running GridSearch for {name}...")
475
- grid = GridSearchCV(model, param_grids[name], cv=5, scoring='accuracy')
476
-
477
- if name in ['LogisticRegression', 'SVC', 'KNN']:
478
- grid.fit(X_train_scaled, y_train)
479
- else:
480
- grid.fit(X_train, y_train)
481
-
482
- best_models[name] = grid.best_estimator_
483
- print(f"Best params for {name}:", grid.best_params_)
484
- print("Best CV Score:", grid.best_score_)
485
- print("=====================================")
486
 
487
  """### BEST PARAMS
488
  ==========================================================================
@@ -611,7 +611,7 @@ classifier = tf.estimator.DNNClassifier(
611
 
612
  classifier.train(
613
  input_fn=lambda: input_fn(train_normalized, train_y_encoded, training=True),
614
- steps=1000
615
  )
616
 
617
  test_y_encoded = le.fit_transform(test_y) #we used sckit label encoder to encode the values better than 1 2 3 4 5
@@ -890,7 +890,4 @@ iface.launch(debug=True)
890
 
891
  # get_ipython().run_line_magic('shell', 'curl https://loca.lt/mytunnelpassword') #getting ur home pass 🥶
892
 
893
- # !npx localtunnel --port 8501 #the tunnel
894
-
895
-
896
-
 
225
  results = []
226
 
227
  counter = 0
228
+ while counter < 100000:
229
  counter += 1
230
 
231
  A0 = round(random.uniform(1.0, 10.0), 2)
 
272
  results = []
273
 
274
  counter = 0
275
+ while counter < 20000:
276
  counter += 1
277
 
278
  A0 = round(random.uniform(1.0, 10.0), 2)
 
358
 
359
  """## Models"""
360
 
361
+ # from sklearn.metrics import accuracy_score
362
 
363
  """### Logistic Regression"""
364
 
365
+ # from sklearn.linear_model import LogisticRegression
366
 
367
+ # lr = LogisticRegression(max_iter=1000, C=10, penalty='l2')
368
+ # lr.fit(X_train_scaled, y_train)
369
+ # lr_pred = lr.predict(X_test_scaled)
370
 
371
+ # print("Logistic Regression Accuracy:", accuracy_score(y_test, lr_pred))
372
 
373
  """### RandomForestClassifier"""
374
 
375
+ # from sklearn.ensemble import RandomForestClassifier
376
 
377
+ # rf = RandomForestClassifier(class_weight='balanced', random_state=42, n_estimators=200, max_depth=None)
378
+ # rf.fit(X_train, y_train)
379
+ # rf_pred = rf.predict(X_test)
380
 
381
+ # print("RandomForestClassifier Accuracy:", accuracy_score(y_test, rf_pred))
382
 
383
  """### Gradient Boosting Classifier"""
384
 
385
+ # from sklearn.ensemble import GradientBoostingClassifier
386
 
387
+ # gb = GradientBoostingClassifier(n_estimators=200, max_depth=5, random_state=42)
388
+ # gb.fit(X_train, y_train)
389
+ # gb_pred = gb.predict(X_test)
390
 
391
+ # print("Gradient Boosting Accuracy:", accuracy_score(y_test, gb_pred))
392
 
393
  """### Support Vector Classifier"""
394
 
395
+ # from sklearn.svm import SVC
396
 
397
+ # svc = SVC(C=10, kernel='rbf', class_weight='balanced')
398
+ # svc.fit(X_train_scaled, y_train)
399
+ # svc_pred = svc.predict(X_test_scaled)
400
 
401
+ # print("SVC Accuracy:", accuracy_score(y_test, svc_pred))
402
 
403
  """### K-Nearest Neighbors"""
404
 
405
+ # from sklearn.neighbors import KNeighborsClassifier
406
 
407
+ # knn = KNeighborsClassifier(n_neighbors=7, weights='uniform')
408
+ # knn.fit(X_train_scaled, y_train)
409
+ # knn_pred = knn.predict(X_test_scaled)
410
 
411
+ # print("KNN Accuracy:", accuracy_score(y_test, knn_pred))
412
 
413
  """### XG Boost"""
414
 
415
+ # from xgboost import XGBClassifier
416
 
417
+ # xgb_model = XGBClassifier(learning_rate=0.1, max_depth=7, n_estimators=200, eval_metric='mlogloss', random_state=42)
418
+ # xgb_model.fit(X_train, y_train)
419
+ # xgb_pred = xgb_model.predict(X_test)
420
 
421
+ # print("XGBoost Accuracy:", accuracy_score(y_test, xgb_pred))
422
 
423
  """### Hyperparameter tuning"""
424
 
425
+ # from sklearn.linear_model import LogisticRegression
426
+ # from sklearn.svm import SVC
427
+ # from sklearn.neighbors import KNeighborsClassifier
428
+ # from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
429
+ # import xgboost as xgb
430
+
431
+ # models = {
432
+ # 'LogisticRegression': LogisticRegression(class_weight='balanced', max_iter=1000),
433
+ # 'SVC': SVC(class_weight='balanced'),
434
+ # 'KNN': KNeighborsClassifier(),
435
+ # 'RandomForest': RandomForestClassifier(class_weight='balanced', random_state=42),
436
+ # 'GradientBoosting': GradientBoostingClassifier(random_state=42),
437
+ # 'XGBoost': xgb.XGBClassifier(eval_metric='mlogloss', random_state=42)
438
+ # }
439
+
440
+
441
+ # param_grids = {
442
+ # 'LogisticRegression': {
443
+ # 'C': [0.1, 1, 10],
444
+ # 'penalty': ['l2']
445
+ # },
446
+ # 'SVC': {
447
+ # 'C': [0.1, 1, 10],
448
+ # 'kernel': ['linear', 'rbf']
449
+ # },
450
+ # 'KNN': {
451
+ # 'n_neighbors': [3, 5, 7],
452
+ # 'weights': ['uniform', 'distance']
453
+ # },
454
+ # 'RandomForest': {
455
+ # 'n_estimators': [100, 200],
456
+ # 'max_depth': [5, 10, None]
457
+ # },
458
+ # 'GradientBoosting': {
459
+ # 'n_estimators': [100, 200],
460
+ # 'max_depth': [3, 5, 7]
461
+ # },
462
+ # 'XGBoost': {
463
+ # 'n_estimators': [100, 200],
464
+ # 'max_depth': [3, 5, 7],
465
+ # 'learning_rate': [0.05, 0.1]
466
+ # }
467
+ # }
468
+
469
+ # from sklearn.model_selection import GridSearchCV
470
+
471
+ # best_models = {}
472
+
473
+ # for name, model in models.items():
474
+ # print(f"Running GridSearch for {name}...")
475
+ # grid = GridSearchCV(model, param_grids[name], cv=5, scoring='accuracy')
476
+
477
+ # if name in ['LogisticRegression', 'SVC', 'KNN']:
478
+ # grid.fit(X_train_scaled, y_train)
479
+ # else:
480
+ # grid.fit(X_train, y_train)
481
+
482
+ # best_models[name] = grid.best_estimator_
483
+ # print(f"Best params for {name}:", grid.best_params_)
484
+ # print("Best CV Score:", grid.best_score_)
485
+ # print("=====================================")
486
 
487
  """### BEST PARAMS
488
  ==========================================================================
 
611
 
612
  classifier.train(
613
  input_fn=lambda: input_fn(train_normalized, train_y_encoded, training=True),
614
+ steps=3000
615
  )
616
 
617
  test_y_encoded = le.fit_transform(test_y) #we used sckit label encoder to encode the values better than 1 2 3 4 5
 
890
 
891
  # get_ipython().run_line_magic('shell', 'curl https://loca.lt/mytunnelpassword') #getting ur home pass 🥶
892
 
893
+ # !npx localtunnel --port 8501 #the tunnel