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, request | |
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 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 | |
from sklearn import preprocessing | |
countryDF = pd.DataFrame({'id' : [101, 102, 103], | |
'country' : ['NZ', 'BR', 'US']}) | |
labelEncode = preprocessing.LabelEncoder() | |
countryDF['countryLabel'] = labelEncode.fit_transform(countryDF['country']) | |
countryDF.drop(['country'], axis=1, inplace=True) | |
print(countryDF) |
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 | |
managerDF = pd.DataFrame({'id':[101, 102, 103, 104, 105, 106, 107, 108], | |
'managerId':['D025', 'A010', 'C020', 'A010', 'D025', 'D025','A010', 'D025']}) | |
# Group by category (managerId), compute sum of values in the category, sort by sum, and rank each value | |
idRank = managerDF.groupby('managerId').size().sort_values().rank().map(int) | |
# Map the ranks of items in the category to its respective item | |
managerDF['managerIdRank'] = managerDF['managerId'].map(idRank) |
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 | |
managerDF = pd.DataFrame({'id':[101, 102, 103, 104, 105, 106, 107, 108], | |
'managerId':['D025', 'A010', 'C020', 'A010', 'D025', 'D025','A010', 'D025']}) | |
managerDF['managerIdCount'] = managerDF['managerId'].map(managerDF.groupby('managerId').size()) | |
managerDF.drop(['managerId'], axis=1, inplace=True) | |
print(managerDF) |
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 | |
from sklearn import preprocessing | |
vehiclerDF = pd.DataFrame({'id':[101, 102, 103, 104, 105, 106, 107, 108], | |
'vehicle':['Car', 'Minivan', 'SUV', 'Car', 'Car', 'Minivan','Car', 'Minivan'], | |
'label':['Yes', 'Yes', 'Yes', 'No', 'Yes', 'No','Yes', 'No']}) | |
# Encode label (target) | |
labelEncode = preprocessing.LabelEncoder() | |
vehiclerDF['label'] = labelEncode.fit_transform(vehiclerDF['label']) |
OlderNewer