-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVDNumericAndCategorical2_regcoeffts.m
40 lines (36 loc) · 1.2 KB
/
SVDNumericAndCategorical2_regcoeffts.m
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
clc;
close all;
clear;
%%
opts = detectImportOptions('AutoData_new.csv','NumHeaderLines',0);
X_true = readtable('AutoData_new.csv',opts);
%%
rng(2);
p = 2;
X_notimputed = X_true{:,:};
matrix_size = numel(X_notimputed);
missingNumber = round(p*0.1*matrix_size);
X_notimputed(randperm(matrix_size, missingNumber))= missing;
NaNed = X_notimputed;
X_imputed = ImputerKeep(NaNed);
%%
y_imputed = X_imputed(:,1);
x_imputed = X_imputed(:,2:end);
x_imputed = [ones(size(y_imputed)) x_imputed];
b_imputed = regress(y_imputed,x_imputed)
%%
y_true = X_true(:,1);
x_true = X_true(:,2:end);
x_true = [ones(size(y_true{:,:})) x_true{:,:}];
b_true = regress(y_true{:,:},x_true)
%%
y_notimputed = X_notimputed(:,1);
x_notimputed = X_notimputed(:,2:end);
x_notimputed = [ones(size(y_notimputed)) x_notimputed];
b_notimputed = regress(y_notimputed,x_notimputed)
%%
plot(1:size(X_true,2),b_imputed,'r--',1:size(X_true,2),b_notimputed,'g*',1:size(X_true,2),b_true,'b')
title({'SVD Imputer Method on Numeric and Categorical Data';'205 Rows, 25 Columns';'15 Numeric Features, 10 Text Feature'})
legend({'True','Nonimputed','Imputed'},'Location','best')
xlabel('Features')
ylabel('Regression Coefficients')