Skip to content

Instantly share code, notes, and snippets.

View oscar-defelice's full-sized avatar
:atom:
Cooking & Coding

Oscar oscar-defelice

:atom:
Cooking & Coding
View GitHub Profile
from fastapi import FastAPI, HTTPException
from ai.services import get_predictions
from core import config
from schemas.schemas import InputData, ResponseDataAPI
app = FastAPI(title=config.PROJECT_NAME, version=config.VERSION, openapi_url="/v1/openapi.json")
@app.get("/status")
config = {
'data': data,
'train_test_ratio': 0.2,
'model_config': {
'model_name': 'house_pricing_model',
'layers': {
'first_layer': 12,
'second_layer': 5,
'output_layer': 1
},
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
num_features = X_train.shape[1]
config = {
'data': data,
'train_test_ratio': 0.2,
'model_config': {
import numpy as np
from sklearn.model_selection import train_test_split
config = {
'data': data,
'train_test_ratio': 0.2
}
def feature_selection(data):
"""
from sklearn.model_selection import train_test_split
X = pd.DataFrame(np.c_[df[df.columns[:-1]]], columns = df.columns[:-1])
Y = df.target
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=42)
correlation_matrix = df.corr().round(2)
# annot = True to print the values inside the square
sns.heatmap(data=correlation_matrix, annot=True);
import seaborn as sns
import matplotlib.pyplot as plt
# seaborn histogram
sns.distplot(boston_dataset.target, hist=True, kde=True,
bins=30, color = 'blue',
hist_kws={'edgecolor':'black'})
# Add labels
plt.title('Histogram of target variable')
plt.xlabel('House examples')
# your client is so famous that has a dataset already in sklearn
from sklearn.datasets import load_boston
boston_dataset = load_boston()
df = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)
async function predict() {
const predictedClass = tf.tidy(() => {
const text = document.getElementById("myText").value;
const tokenisation = tokenise(text, word2index);
const predictions = model.predict(tf.tensor2d(tokenisation, [1, maxLen]));
return predictions.as1D().argMax();
});
const classId = (await predictedClass.data())[0];
var predictionText = "";
switch(classId){
async function loadModel() {
const model = await tf.loadLayersModel(modelPath);
return model;
}