Open liangkyle08 opened 3 months ago
Show algorithms and preparation of data for analysis. This includes cleaning, encoding, and one-hot encoding.
function calculateSurvival() {
// Extract data from AI model
extractData()
.then((AIData) => {
// Prepare passenger data
const passengerData = {
name: document.getElementById("name").value,
pclass: parseInt(getCheckedCheckboxValue("pclass")),
sex: AIData[0],
age: AIData[1],
sibsp: parseInt(document.getElementById("sibsp").value),
parch: parseInt(document.getElementById("parch").value),
fare: parseFloat(document.getElementById("fare").value),
embarked: getCheckedCheckboxValue("embarked"),
alone: document.getElementById("alone").value === "true" ? true : false,
};
// Prepare body for POST request
const body = {
passenger: passengerData,
};
// Options for the POST request
const post_options = {
method: "POST",
cache: "no-cache",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "include",
},
};
// Send POST request to server
fetch(url, post_options)
.then((response) => {
if (!response.ok) {
const errorMsg = response.status;
console.log(errorMsg);
return;
}
return response.json();
})
.then((data) => {
// Update UI with survival data
const h1 = document.getElementById("survival");
h1.textContent = data[0];
})
.catch((err) => {
// Handle errors
console.error(err);
});
})
.catch((err) => {
// Handle errors from AI data extraction
console.error(err);
});
}
# data extraction
data = information[0] # get the first element
age = data["age"] # age extraction
bothGenders = data["gender"] # get both gender confidence rates
woman = bothGenders["Woman"] # woman confidence
man = bothGenders["Man"] # man confidence
# based on the probabilities, find which is larger and return that
gender = None
if woman > man:
gender = "Female"
elif woman < man:
gender = "Male"
# the order is very important (must be gender THEN age)
returnData = [gender, age] # create a list and send it
return returnData # return
Show algorithms and preparation for predictions.
def load_model(url="https://github.com/serengil/deepface_models/releases/download/v1.0/age_model_weights.h5") -> Model:
"""
Construct age model, download its weights and load
Returns:
model (Model)
"""
# Construct base model
model = VGGFace.base_model()
# Add layers for age prediction
classes = 101
base_model_output = Sequential()
base_model_output = Convolution2D(classes, (1, 1), name="predictions")(model.layers[-4].output)
base_model_output = Flatten()(base_model_output)
base_model_output = Activation("softmax")(base_model_output)
# Construct age model
age_model = Model(inputs=model.input, outputs=base_model_output)
# Load weights
home = folder_utils.get_deepface_home()
if os.path.isfile(home + "/.deepface/weights/age_model_weights.h5") != True:
logger.info("age_model_weights.h5 will be downloaded...")
output = home + "/.deepface/weights/age_model_weights.h5"
gdown.download(url, output, quiet=False)
age_model.load_weights(home + "/.deepface/weights/age_model_weights.h5")
return age_model
Linear regression is a method used to model the relationship between a dependent variable and one or more independent variables by fitting a linear equation to observed data. In data preparation, cleaning involves handling missing values and outliers, while encoding categorical variables ensures compatibility with the model. One-hot encoding, for example, is used when dealing with categorical data. In the provided code snippets, data extraction and encoding are essential steps for preparing data for analysis, such as extracting gender and age information from a dataset. Linear regression models aim to find the best-fitting line that describes the relationship between variables, facilitating predictions based on this linear relationship.
Decision trees are hierarchical structures used for both classification and regression tasks, where each internal node represents a decision based on a feature, and each leaf node represents a prediction or outcome. Data preparation involves similar steps to linear regression, focusing on cleaning and preprocessing. However, decision tree algorithms are capable of handling categorical variables inherently without needing explicit encoding. In the provided example, the decision-making process based on confidence rates for gender can be likened to a decision tree node making splits based on certain conditions. Decision tree analysis simplifies complex decision-making processes into a series of if-else conditions, providing clear paths for predictions.
From VSCode using SQLite3 Editor, show your unique collection/table in database, display rows and columns in the table of the SQLite database.
From VSCode model, show your unique code that was created to initialize table and create test data.
def initMessages():
with app.app_context():
"""Create database and tables"""
db.create_all()
"""Tester data for table"""
m1 = Message(uid='toby', message='Hello from Thomas Edison', likes=3)
m2 = Message(uid='niko', message='Greetings from Nicholas Tesla', likes=0)
m3 = Message(uid='lex', message='Welcome from Alexander Graham Bell', likes=27)
m4 = Message(uid='hop', message='Good day from Grace Hopper', likes=-74)
messages = [m1, m2, m3, m4]
"""Add message data to the table"""
for message in messages:
try:
message.create()
except IntegrityError:
'''fails with bad or duplicate data'''
db.session.remove()
print(f"Records exist, duplicate message, or error: {message.uid}")
Reviewer: Anvay Yadav Completedness: 0.9/1 Neatness: 1/1 +0.05 (extra credit)
I think this is a good issue but you could add more screenshots detailing the code and write more text explaining the code. Everything is super neat, so full points for that. You have everything, but doing a bit more will get you the last few points. Extra credit earns you 0.05 extra.
1.95/2 = 97.5%
APIs and JSON
In VSCode, show Python API code definition for request and response using GET, POST, UPDATE methods. Discuss algorithmic condition used to direct request to appropriate Python method based on request method.
api.add_resource(MessageAPI._CRUD, '/') api.add_resource(MessageAPI._Send, '/send') api.add_resource(MessageAPI._Delete, '/delete') api.add_resource(MessageAPI._Likes, '/like')
In Postman, show URL request and Body requirements for GET, POST, and UPDATE methods. In Postman, show the JSON response data for 200 success conditions on GET, POST, and UPDATE methods.
![Screenshot 2024-04-17 114913](https://github.com/BearytheGreenBear/csp-blog/assets/90527109/9e625552-211f-4281-82ca-d6b02c925bc0)
In Postman, show the JSON response for error for 400 when missing body on a POST request.![image](https://github.com/BearytheGreenBear/csp-blog/assets/90527109/2b9e5bc0-7973-4f79-986a-27f301b7656e)
In Postman, show the JSON response for error for 404 when providing an unknown user ID to a UPDATE request.![image](https://github.com/BearytheGreenBear/csp-blog/assets/90527109/c03af590-969b-4f98-8f4e-3a4e31ac9c82)
Blog JavaScript API fetch code and formatting code to display JSON.
In Chrome inspect, show response of JSON objects from fetch of GET, POST, and UPDATE methods. In the Chrome browser, show a demo (GET) of obtaining an Array of JSON objects that are formatted into the browsers screen.![image](https://github.com/BearytheGreenBear/csp-blog/assets/90527109/ac3741fd-571d-4105-9ef9-ee10d7a60cf7)
In JavaScript code, show code that performs iteration and formatting of data into HTML.
In the Chrome browser, show a demo (POST or UPDATE) gathering and sending input and receiving a response that show update. Repeat this demo showing both success and failure.![image](https://github.com/BearytheGreenBear/csp-blog/assets/90527109/e4214d18-aafb-4614-8c48-1632c4f154ea)
In JavaScript code, describe fetch and method that obtained the Array of JSON objects. In JavaScript code, show and describe code that handles success. Describe how code shows success to the user in the Chrome Browser screen. In JavaScript code, show and describe code that handles failure. Describe how the code shows failure to the user in the Chrome Browser screen.