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
#### This REFERENCE file contains frequently used R codes #### | |
# To detach a library that is already loaded in R Environment, without restarting R console- | |
detach("package:mlr", unload=TRUE) | |
# To install single package | |
install.packages("mlr") | |
# To install multiple packages | |
install.packages(c("mlr", "xgboost")) |
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
# This is a sample model to demonstrate how a Machine Learning model | |
# can be implemented in Production as a REST API and how it can be consumed | |
# Import libraries and packages | |
from sklearn import svm, datasets | |
import pickle | |
import numpy as np | |
# Load Sample data | |
iris = datasets.load_iris() |
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 Flask class from the flask module | |
from flask import Flask | |
import numpy as np | |
import pickle | |
# Create Flask object to run | |
app = Flask(__name__) | |
@app.route('/') |
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 libraries | |
import numpy as np | |
import pandas as pd | |
from sklearn.ensemble import RandomForestRegressor | |
# load data file | |
train = pd.read_csv('50-Startups.csv') | |
# perform one-hot encoding for categorical variable | |
trainDummies = pd.get_dummies(train['State'], prefix = 'state') |
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 pandas as pd | |
country = ['NZ', 'BR', 'US'] | |
onehotDF = pd.get_dummies(country) | |
print(onehotDF) |
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 pandas as pd | |
import numpy as np | |
platformDF = pd.DataFrame({'id' : [101, 102, 103, 104, 105, 106], | |
'platform' : ['Android', 'Android', 'iOS', np.nan, 'Android', 'iOS']}) | |
platformDF.platform = platformDF.platform.fillna('NaN') | |
onehotDF = pd.get_dummies(platformDF) | |
print(onehotDF) |
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 pandas as pd | |
gadgetDF = pd.DataFrame({'gadgetId' : [101, 102, 103, 104, 105], | |
'gadgetName' : ['Apple_iPhone_6', | |
'Apple_iPad_3', | |
'Samsung_Galaxy_S8', | |
'Samsung_Galaxy_S9', | |
'Google_Pixel_3']}) | |
dummyDF = gadgetDF['gadgetName'].apply(lambda x: pd.Series(x.split('_'))) |
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 pandas as pd | |
incExpDF = pd.DataFrame({'id' : [101, 102, 103, 104, 105], | |
'familyCnt' : [2, 4, 3, 3, 5], | |
'totalInc' : [68000, 72000, 34000, 44000, 52000], | |
'totalExp' : [48000, 66000, 33000, 41000, 50000]}) | |
incExpDF['incPerPerson'] = incExpDF['totalInc'] / incExpDF['familyCnt'] | |
incExpDF['expPerPerson'] = incExpDF['totalExp'] / incExpDF['familyCnt'] | |
incExpDF['savingsPerPerson'] = incExpDF['incPerPerson'] - incExpDF['expPerPerson'] |
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
# Initalize webcam. 0 starts built-in camera | |
cap = cv2.VideoCapture(0) | |
# Specify HSV range of Tennis Ball | |
ballHSVLower = np.array([25, 75, 85]) | |
ballHSVUpper = np.array([50, 220, 255]) | |
while True: | |
# Read captured webcam frame | |
_, frame = cap.read() |
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 libraries | |
import numpy as np | |
import pandas as pd | |
import eli5 | |
from sklearn.ensemble import RandomForestRegressor | |
from sklearn.model_selection import train_test_split | |
from eli5.sklearn import PermutationImportance | |
# load data file |
OlderNewer