This Python script creates a password-protected ZIP file using the pyzipper library. It allows you to specify the files to include in the ZIP and set a password for encryption. The resulting ZIP file requires the provided password to access its contents, providing an additional layer of security.
For this exercise, you will create a simple neural network example in an AWS SageMaker notebook. We'll use a synthetic dataset to predict whether a customer will make a purchase based on two features:
Website visit duration
Number of pages visited.
This is a binary classification problem, and we'll use a small neural network for quick execution.
Step 1: Set Up AWS SageMaker Notebook
Launch a new SageMaker notebook instance.
Open a new Jupyter notebook in the instance.
Choose kernel conda_tensorflow2_p310.
Step 2: Generate Synthetic Data
import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
Generating synthetic data
np.random.seed(0)
data_size = 200
features = np.random.rand(data_size, 2) # Two features: visit duration and pages visited
labels = (features[:, 0] + features[:, 1] > 1).astype(int) # Purchase (1) or not (0)
Step 4: Build and Train the Neural Network
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Define the model
model = Sequential([
Dense(10, activation='relu', input_shape=(2,)), # Input layer with 2 features
Dense(1, activation='sigmoid') # Output layer with sigmoid activation for binary classification
])
This exercise introduces you to the basics of using AWS SageMaker for building and training a simple neural network with synthetic data. The model predicts customer purchase behavior, a typical business problem, using a fast and straightforward neural network architecture.
For this exercise, you will create a simple neural network example in an AWS SageMaker notebook. We'll use a synthetic dataset to predict whether a customer will make a purchase based on two features:
Website visit duration Number of pages visited.
This is a binary classification problem, and we'll use a small neural network for quick execution.
Step 1: Set Up AWS SageMaker Notebook Launch a new SageMaker notebook instance. Open a new Jupyter notebook in the instance. Choose kernel conda_tensorflow2_p310.
Step 2: Generate Synthetic Data import numpy as np import pandas as pd import warnings
warnings.filterwarnings('ignore')
Generating synthetic data
np.random.seed(0) data_size = 200 features = np.random.rand(data_size, 2) # Two features: visit duration and pages visited labels = (features[:, 0] + features[:, 1] > 1).astype(int) # Purchase (1) or not (0)
Convert to DataFrame for easier manipulation
df = pd.DataFrame(features, columns=['VisitDuration', 'PagesVisited']) df['Purchase'] = labels
Step 3: Preprocess the Data from sklearn.model_selection import train_test_split
Split the data
X_train, X_test, y_train, y_test = train_test_split(df[['VisitDuration', 'PagesVisited']], df['Purchase'], test_size=0.2, random_state=42)
Step 4: Build and Train the Neural Network import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense
Define the model
model = Sequential([ Dense(10, activation='relu', input_shape=(2,)), # Input layer with 2 features Dense(1, activation='sigmoid') # Output layer with sigmoid activation for binary classification ])
Compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
Train the model
model.fit(X_train, y_train, epochs=10, batch_size=10)
Step 5: Evaluate the Model
Evaluate the model on the test set
loss, accuracy = model.evaluate(X_test, y_test) print(f"Test Accuracy: {accuracy}")
This exercise introduces you to the basics of using AWS SageMaker for building and training a simple neural network with synthetic data. The model predicts customer purchase behavior, a typical business problem, using a fast and straightforward neural network architecture.