Maltab-Machine Learning-Importing and Preprocessing Data

Make a Datastore

Instructions are in the task pane to the left. Complete and submit each task one at a time.

 

Task 1

letterds = datastore("*_M_*.txt")

Task 2

data=read(letterds)

Task 3

plot(data.X,data.Y)

Task 4

data = read(letterds)

plot(data.X,data.Y)

Task 5

data = readall(letterds)

plot(data.X,data.Y)

Add a Preprocessing Function

Instructions are in the task pane to the left. Complete and submit each task one at a time.

This code creates a datastore, imports data, and visualizes it.

letterds = datastore("*_M_*.txt");

data = read(letterds);

data = scale(data);

plot(data.X,data.Y)

axis equal

plot(data.Time,data.Y)

ylabel("Vertical position")

xlabel("Time")

Task 2

preprocds = transform(letterds,@scale)

Task 3

data = readall(preprocds)

plot(data.Time,data.Y)

Tasks 1, 4, & 5

function data = scale(data)

data.Time = (data.Time - data.Time(1))/1000;

data.X = 1.5*data.X;

data.X = data.X - mean(data.X,"omitnan");

data.Y = data.Y - mean(data.Y,"omitnan");

end

% Any calculations (including the default use of functions such as mean) involving NaNs will result in NaN. This is important in machine learning, where you often have missing values in your data. In the handwriting data, a NaN occurs wherever the writer lifted the pen from the tablet.

% You can use the "omitnan" option to have statistical functions like mean ignore missing values.mean(x,"omitnan")

 

Guess you like

Origin blog.csdn.net/seek97/article/details/108389327