Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Iris Species Classification with PySpark

This Jupyter Notebook demonstrates Iris species classification using PySpark, a popular framework for large-scale data processing.

Steps:

  1. Install PySpark: The code snippet highlights installing PySpark within the notebook itself using !pip install pyspark.

  2. Import Libraries: Necessary libraries like pyspark.sql for Spark functionalities and pandas for data manipulation are imported.

  3. Create Spark Session: A Spark session object is created, which acts as the entry point for interacting with Spark functionalities.

  4. Import Dataset:

    • The code assumes a pre-defined function load_iris to load the Iris dataset.
    • The loaded data is converted to a Spark DataFrame using spark.createDataFrame.
  5. Preliminary Checks:

    • The printSchema method is used to understand the schema (column names and data types) of the DataFrame.
  6. Feature Engineering:

    • VectorAssembler is used to combine relevant features (sepal length, sepal width, petal length, petal width) into a single feature vector named Features.
  7. Select Required Columns:

    • The DataFrame is filtered to include only the feature vector and the target column (target), representing the Iris species.
  8. Split the Dataset:

    • The DataFrame is split into training and testing sets using randomSplit for model evaluation.
  9. Model Training:

    • A Naive Bayes model is chosen for classification. The model is instantiated with feature and target column names and then trained on the training data using the fit method.
  10. Predictions:

  • The transform method is used on the testing data to generate predictions for each data point.
  1. Evaluation:
  • The confusion matrix is calculated to visualize the performance of the model on a per-class basis. This helps identify how well the model classified each Iris species.
  • MulticlassClassificationEvaluator is used to calculate the model's accuracy.

Note:

  • The provided code snippet concludes with a note about Colab paid products, which can be ignored for the Iris classification task.

Key Differences from Sentiment Analysis

This example focuses on classification tasks using PySpark. Sentiment analysis, however, deals with analyzing text data to determine the sentiment (positive, negative, or neutral) expressed within the text. The key differences lie in:

  • Data Type: Text data (news articles) for sentiment analysis vs. structured data (Iris dataset) with numerical features for classification.
  • Libraries: Libraries like scikit-learn are commonly used for sentiment analysis, while PySpark is used for large-scale data processing tasks.
  • Preprocessing: Text data cleaning (removing punctuation, stop words, etc.) is crucial for sentiment analysis, while feature engineering might involve creating new features or scaling existing ones for classification tasks.
  • Models: Different machine learning models like Random Forest or LSTMs might be preferred for sentiment analysis depending on the complexity of the text data.

About

This Jupyter Notebook uses PySpark to classify Iris species based on petal and sepal measurements. It achieves an impressive 97% accuracy using a Naive Bayes model!

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages