Designing Neural Network Architectures
Example Prompt:
Example Response:
Related Tasks:
Data Cleaning and Transformation
Example Prompt:
Example Response:
import pandas as pd
df = pd.read_csv('your_file.csv')
missing_values = df.isnull().sum()
print(missing_values)
df['column_name'].fillna(df['column_name'].mean(), inplace=True)
Q1 = df['column_name'].quantile(0.25)
Q3 = df['column_name'].quantile(0.75)
IQR = Q3 - Q1
lower_bound = Q1 - 1.5 * IQR
upper_bound = Q3 + 1.5 * IQR
outliers = df[(df['column_name'] < lower_bound) | (df['column_name'] > upper_bound)]
df.loc[df['column_name'] < lower_bound, 'column_name'] = lower_bound
df.loc[df['column_name'] > upper_bound, 'column_name'] = upper_bound
Related Tasks:
Training Machine Learning Models
Example Prompt:
Example Response:
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
# Impute missing values
imputer = SimpleImputer(strategy='mean')
df['numerical_column'] = imputer.fit_transform(df[['numerical_column']])
# Encode categorical variables
df = pd.get_dummies(df, columns=['categorical_column'])
# Split the data
X = df.drop('target', axis=1)
y = df['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, max_depth=None, random_state=42)
model.fit(X_train, y_train)
from sklearn.model_selection import GridSearchCV
param_grid = {
'n_estimators': [100, 200],
'max_depth': [None, 10, 20],
'min_samples_leaf': [1, 2, 4]
}
grid_search = GridSearchCV(RandomForestClassifier(random_state=42), param_grid, cv=5)
grid_search.fit(X_train, y_train)
best_model = grid_search.best_estimator_
from sklearn.metrics import classification_report
y_pred = best_model.predict(X_test)
print(classification_report(y_test, y_pred))
importances = best_model.feature_importances_
feature_importance_df = pd.DataFrame({'Feature': X.columns, 'Importance': importances})
feature_importance_df.sort_values(by='Importance', ascending=False, inplace=True)
print(feature_importance_df)
Related Tasks:
Deploying AI Models to Production
Example Prompt:
Example Response:
FROM python:3.9-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
package1 \
package2 \
&& rm -rf /var/lib/apt/lists/*
__pycache__/
*.pyc
.git/
.env
ENV MODEL_PATH=/app/model
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
FROM builder AS build
# Build steps here
FROM python:3.9-slim
COPY --from=builder /app /app
RUN useradd -m myuser
USER myuser
HEALTHCHECK CMD curl --fail http://localhost:8000/ || exit 1
Related Tasks:
Creating Technical Documentation
Example Prompt:
Example Response:
## Endpoint: Get User
**GET** `/api/users/{id}`
### Request Parameters
- `id` (required): The ID of the user.
### Response
{
"id": 1,
"name": "John Doe"
}
### Example Request
curl -X GET 'https://api.example.com/users/1' -H 'Authorization: Bearer YOUR_API_KEY'
### Example Response
{
"id": 1,
"name": "John Doe"
}
### Error Codes
- `404`: User not found.
- `401`: Unauthorized access.
Related Tasks: