text_plain_output_1.png
from pyspark.ml.feature import StringIndexer, VectorIndexer, StringIndexerModel, IndexToString

from pyspark.ml.feature import VectorAssembler

from pyspark.sql import SparkSession

import pandas as pd
import pyspark
from pyspark.ml.classification import DecisionTreeClassifier
from pyspark.ml.linalg import Vectors
from pyspark.ml.feature import VectorAssembler
from pyspark.ml import Pipeline
from pyspark.sql import SparkSession
from pyspark.ml.feature import StringIndexer, VectorIndexer, StringIndexerModel, IndexToString
spark = SparkSession.builder.getOrCreate()

train = spark.read.format('csv').load('/kaggle/input/dataset/train.csv', header='True', inferSchema='True')
test = spark.read.format('csv').load('/kaggle/input/dataset/test.csv', header='True', inferSchema='True')

labelIndexer = StringIndexer(inputCol='acceptability', outputCol='label')
buyIndexer = StringIndexer(inputCol='buying_price', outputCol='iBuyingPrice')
id2 = StringIndexer(inputCol='maintenance_price', outputCol='iMain')
id3 = StringIndexer(inputCol='number_of_doors', outputCol='iDoor')
id4 = StringIndexer(inputCol='carry_capacity', outputCol='iCarry')
id5 = StringIndexer(inputCol='trunk_size', outputCol='iTrunk')
id6 = StringIndexer(inputCol='safety', outputCol='iSefety')
indexedLabelTrain = labelIndexer.fit(train).transform(train)
df2 = buyIndexer.fit(indexedLabelTrain).transform(indexedLabelTrain)
df3 = id2.fit(df2).transform(df2)
df4 = id3.fit(df3).transform(df3)
df5 = id4.fit(df4).transform(df4)
df6 = id5.fit(df5).transform(df5)
df7 = id6.fit(df6).transform(df6)

assembler = VectorAssembler(inputCols=['iBuyingPrice', 'iMain', 'iDoor', 'iCarry', 'iTrunk', 'iSefety'], outputCol='features')
df8 = assembler.transform(df7)
df8.show(5)