This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np # linear algebra | |
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import confusion_matrix | |
from sklearn.metrics import roc_auc_score | |
from sklearn.metrics import classification_report | |
from sklearn.datasets import make_multilabel_classification | |
from xgboost import XGBClassifier | |
from sklearn.model_selection import KFold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cr_y1 = classification_report(ytest[:,0],yhat[:,0]) | |
cr_y2 = classification_report(ytest[:,1],yhat[:,1]) | |
cr_y3 = classification_report(ytest[:,2],yhat[:,2]) | |
cr_y4 = classification_report(ytest[:,3],yhat[:,3]) | |
cr_y5 = classification_report(ytest[:,4],yhat[:,4]) | |
print (cr_y1) | |
----------------------------- | |
precision recall f1-score support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cm_y1 = confusion_matrix(ytest[:,0],yhat[:,0]) | |
cm_y2 = confusion_matrix(ytest[:,1],yhat[:,1]) | |
cm_y3 = confusion_matrix(ytest[:,2],yhat[:,2]) | |
cm_y4 = confusion_matrix(ytest[:,3],yhat[:,3]) | |
cm_y5 = confusion_matrix(ytest[:,4],yhat[:,4]) | |
print (cm_y1) | |
--------------- | |
[[1053 140] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auc_y1 = roc_auc_score(ytest[:,0],yhat[:,0]) | |
auc_y2 = roc_auc_score(ytest[:,1],yhat[:,1]) | |
auc_y3 = roc_auc_score(ytest[:,2],yhat[:,2]) | |
auc_y4 = roc_auc_score(ytest[:,3],yhat[:,3]) | |
auc_y5 = roc_auc_score(ytest[:,4],yhat[:,4]) | |
print("ROC AUC y1: %.4f, y2: %.4f, y3: %.4f, y4: %.4f, y5: %.4f" % (auc_y1, auc_y2, auc_y3, auc_y4, auc_y5)) | |
------------------------------------------------------- | |
ROC AUC y1: 0.8230, y2: 0.8025, y3: 0.8091, y4: 0.8005, y5: 0.8086 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classifier = MultiOutputClassifier(XGBClassifier()) | |
clf = Pipeline([('classify', classifier)]) | |
print (clf) | |
------------------------------------------------ | |
Pipeline(steps=[('classify', | |
MultiOutputClassifier(estimator=XGBClassifier(base_score=None, | |
booster=None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(5): | |
print(x[i]," =====> ", y[i]) | |
---------------------------------------------------------------------------------- | |
[5. 4. 0. 4. 3. 0. 1. 1. 0. 3. 0. 1. 6. 0. 0. 2. 0. 1. 6. 1.] =====> [1 0 0 0 0] | |
[2. 2. 0. 1. 5. 1. 2. 0. 7. 4. 1. 0. 2. 1. 5. 2. 0. 4. 0. 6.] =====> [0 0 0 0 1] | |
[3. 4. 2. 1. 4. 5. 2. 2. 4. 1. 1. 2. 3. 5. 2. 3. 0. 4. 5. 2.] =====> [0 1 0 1 0] | |
[0. 5. 2. 3. 2. 3. 7. 4. 4. 1. 3. 0. 5. 5. 2. 1. 3. 3. 2. 3.] =====> [0 0 0 0 0] | |
[3. 6. 2. 3. 2. 0. 1. 3. 2. 4. 0. 0. 3. 4. 1. 6. 0. 5. 0. 8.] =====> [1 0 0 0 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np # linear algebra | |
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import confusion_matrix | |
from sklearn.metrics import roc_auc_score | |
from sklearn.metrics import classification_report | |
from sklearn.datasets import make_multilabel_classification | |
from xgboost import XGBClassifier | |
from sklearn.model_selection import KFold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longestPalindrome(s): | |
return find_LPS_recursive(st, 0, len(st)-1) | |
def find_LPS_recursive(s, s_Index, e_Index): | |
if s_Index > e_Index: | |
return 0 | |
if s_Index = endIndex: | |
return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic Solution | |
def calFib(n): | |
if n < 2: | |
return n | |
return calFib(n-1) + calFib(n-2) | |
# Top-down DP with Memorization | |
def calculateFibonacci(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unbound_knapsack(profits, weights, capacity): | |
n = len(profits) | |
# base case | |
if capacity <= 0 or n == 0 or len(weights) != n: | |
return 0 | |
dp = [[-1 for _ in range(capacity+1)] for _ in range(len(profits))] | |
# initiaite the capacity = 0 columns |
NewerOlder