יסודות בינה מלאכותית : 10-RB27 – מבוא לרשת ניירונים
- תרגול כיתה יחד : התקנה של סביבית עבודה – לבינה מלאכותית עבור אנקודנה שלב אחר שלב
- ניפתח את :
- ונפעיל את התוכנית
conda create -n face_env python=3.8
conda activate face_env
pip install opencv-python
pip install numpy==1.21
for face detection :
pip install dlib
pip install face_recognition
pip install matplotlib
conda install jupyter notebook -y
jupyter notebook –version
2. הרצה של בינה מלאכותית מאוד פשוטה – לזיהוי פנים הורדת תמונות – תרגול כיתה
3. רשות ניירונים
4. ניתוח קובץ אקסל ושימוש ברשת ניירונים
4.1 שים לב שאנחנו ב BASE באנקודנה
4.2 התקנה סיפריות אם צריך
1 2 3 4 5 6 7 8 |
pip install pandas pip install numpy pip install tensorflow pip install scikit-learn pip install matplotlib tqdm (optional, for a progress bar in Jupyter Notebooks) # pip install tqdm |
4.2.1 נבדוק שהכל הותקן
1 2 3 4 5 6 7 8 |
import pandas as pd import numpy as np import tensorflow as tf from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler import matplotlib.pyplot as plt print("All packages imported successfully!") |
1 |
pip install pandas seaborn matplotlib |
4.3 נוריד את הקובץ עבוד בינה מלאכותית מסוג ANN
USA Housing Dataset1
4.4 נריץ את הקוד באנקודנה Jupiter notebook
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import os import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # Check if the file exists file_path = r'd:\temp\USA Housing Dataset1.csv' if os.path.exists(file_path): print("File found.") else: raise FileNotFoundError("File not found. Check the path.") # Load the dataset data = pd.read_csv(file_path) # Display the first few rows to understand the structure print("Dataset Preview:") print(data.head()) # Remove rows where 'price-usd' is zero or negative data = data[data['price-usd'] > 0] # Display basic statistics print("\nDataset Statistics:") print(data.describe()) # Select numeric columns for correlation analysis numeric_features = data.select_dtypes(include=['float64', 'int64']).columns # Correlation matrix correlation_matrix = data[numeric_features].corr() # Plot heatmap of correlation matrix plt.figure(figsize=(10, 8)) sns.heatmap(correlation_matrix, annot=True, fmt='.2f', cmap='coolwarm', cbar=True) plt.title('Correlation Heatmap') plt.show() # Analyze correlation with house price price_correlation = correlation_matrix['price-usd'].sort_values(ascending=False) print("\nCorrelation with 'price-usd':") print(price_correlation) # Scatter plots for top correlated features top_features = price_correlation.index[1:4] # Select top 3 features excluding 'price-usd' for feature in top_features: plt.figure(figsize=(6, 4)) sns.scatterplot(data=data, x=feature, y='price-usd') plt.title(f"Price vs {feature}") plt.xlabel(feature) plt.ylabel('Price (USD)') plt.show() # Save the correlation matrix to a CSV file correlation_output_path = r'd:\temp\correlation_matrix.csv' correlation_matrix.to_csv(correlation_output_path) print(f"Correlation matrix saved to: {correlation_output_path}") |
4.3 רשת ניירונים וניתוח קובץ אקבל בקוד ( נשווה מול CHATGPT מול קוד בהמשך )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
import pandas as pd import numpy as np import tensorflow as tf from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler import matplotlib.pyplot as plt import os # Load the dataset file_path = r'd:\temp\USA Housing Dataset1.csv' if os.path.exists(file_path): print("File found.") else: print("File not found. Check the path.") data = pd.read_csv(file_path) print("File loaded into memory.") # Remove rows where 'price-usd' is zero data = data[data['price-usd'] > 0] # Normalize target (price) data['price-usd'] = data['price-usd'] / 1e6 # Scale target to millions of dollars # Prepare features and target X = data[['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'waterfront', 'view', 'condition', 'sqft_above', 'sqft_basement', 'yr_built']].values y = data['price-usd'].values # Split the data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Standardize the features scaler = StandardScaler() X_train = scaler.fit_transform(X_train) X_test = scaler.transform(X_test) # Define the ANN model input_size = X_train.shape[1] hidden_size = 32 output_size = 1 # Define the model with Input layer model = tf.keras.Sequential([ tf.keras.layers.Input(shape=(input_size,)), # Explicit input shape tf.keras.layers.Dense(hidden_size, activation='relu'), tf.keras.layers.Dense(hidden_size, activation='relu'), tf.keras.layers.Dense(output_size) ]) # Compile the model model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001), loss='mse') # Train the model history = model.fit(X_train, y_train, epochs=1000, validation_data=(X_test, y_test), verbose=1) # Plot training and validation loss plt.figure(figsize=(10, 6)) plt.plot(history.history['loss'], label='Training Loss', marker='o') plt.plot(history.history['val_loss'], label='Validation Loss', marker='x') plt.title('Training and Validation Loss History') plt.xlabel('Epoch') plt.ylabel('Loss') plt.legend() plt.grid(True) plt.show() # Evaluate the model on the test dataset y_pred_test = model.predict(X_test).flatten() # Calculate accuracy for each prediction accuracy = 100 * (1 - np.abs(y_pred_test - y_test) / y_test) # Handle cases where actual price is zero (to avoid division by zero) accuracy = np.where(y_test == 0, 0, accuracy) # Create a DataFrame for predictions, actual prices, and accuracy evaluation_df = pd.DataFrame({ 'Predicted Price (Million $)': y_pred_test, 'Actual Price (Million $)': y_test, 'Accuracy (%)': accuracy }) # Display first 10 rows of the table print("\nEvaluation: Predicted vs Actual Prices with Accuracy") print(evaluation_df.head(10)) # Save the evaluation table to a CSV file evaluation_df.to_csv(r'd:\temp\evaluation_results_with_accuracy.csv', index=False) # Plot Predicted vs Actual Prices plt.figure(figsize=(10, 6)) plt.scatter(evaluation_df['Actual Price (Million $)'], evaluation_df['Predicted Price (Million $)'], alpha=0.7) plt.xlabel('Actual Price (Million $)') plt.ylabel('Predicted Price (Million $)') plt.title('Predicted vs Actual Prices') plt.plot([evaluation_df['Actual Price (Million $)'].min(), evaluation_df['Actual Price (Million $)'].max()], [evaluation_df['Actual Price (Million $)'].min(), evaluation_df['Actual Price (Million $)'].max()], color='red', linestyle='--', label='Perfect Prediction Line') plt.legend() plt.grid(True) plt.show() |
4.4 נתח את הקוד דרך CHATGPT איפה לדעתך יותר קל
טען את הקובץ ל CHATGPT בקש ממנו לנתח את הנתונים ולמצוא קשרים ולתת ניתוח מיללוי ברור על מגמה מובליה ואיפה הכי משתלם עבור השקעה
5. RUNWAY צפה בסרטון והעזר במדריך לפי הצורך