Convert matrix columns to z scores - notation
I am doing a course on machine learning. In it I am asked to convert a matrix's columns to z-scores. It says:
Subtract the mean value of each feature from the dataset (columns of
X). After subtracting the mean, additionally scale (divide) the
feature values by their respective “standard deviations.”
This is not hard for me and I have written a little python function to this goal, but I was wondering what the vectorized version of this function would look like. So I set up some equations that I could then express in python, but I have done some unconventional things to achieve this and I would like to know what the conventional way would be.
Here is what I've got:
$$
z: R^{mtimes n}rightarrow R^{mtimes n}\
z( X) =left( X-1_{m} mu ( x)^{T}right) otimes 1_{m} sigma ( x)^{T}\
$$
Insecurities:
- The circle operator in this equation is the hadamard product. Does this even have an official operator? Should I describe what is meant with that operator? Or is there some way around it?
- I've added the function's mapping on top as is usual in certain programming languages like Haskell. I find this to be very handy in terms of doing linear algebra where you have to keep track of the dimensions of vectors and matrices. Is this common in expressing math as well?
Here are mu and sigma:
$$
mu :R^{mtimes n} rightarrow R^{n}\
mu ( X) =frac{1}{m} x^{T} 1_{m}\
$$
Same insecurities here.
$$
sigma : R^{mtimes n}rightarrow R^{n}\
sigma ( X) =frac{1}{m}sqrt{left(sumlimits ^{n}_{j=0}left( X-1_{m} mu ( x)^{T}right)^{2}_{ij}right)_{j}}\
$$
Insecurities:
- I have to square each cell of the resulting matrix and sum the results in to a vector. I am using a fictional
i
index. How should I describe what i is? - I later have to square each element of the vector. Here I use
j
, but outside the summation. Again: how should I describe this?
Your insights are much appreciated as I would like to learn the right/conventional way of doing linear algebra and don't have access to a teacher. I am curious to know how would your solution would look like.
linear-algebra
add a comment |
I am doing a course on machine learning. In it I am asked to convert a matrix's columns to z-scores. It says:
Subtract the mean value of each feature from the dataset (columns of
X). After subtracting the mean, additionally scale (divide) the
feature values by their respective “standard deviations.”
This is not hard for me and I have written a little python function to this goal, but I was wondering what the vectorized version of this function would look like. So I set up some equations that I could then express in python, but I have done some unconventional things to achieve this and I would like to know what the conventional way would be.
Here is what I've got:
$$
z: R^{mtimes n}rightarrow R^{mtimes n}\
z( X) =left( X-1_{m} mu ( x)^{T}right) otimes 1_{m} sigma ( x)^{T}\
$$
Insecurities:
- The circle operator in this equation is the hadamard product. Does this even have an official operator? Should I describe what is meant with that operator? Or is there some way around it?
- I've added the function's mapping on top as is usual in certain programming languages like Haskell. I find this to be very handy in terms of doing linear algebra where you have to keep track of the dimensions of vectors and matrices. Is this common in expressing math as well?
Here are mu and sigma:
$$
mu :R^{mtimes n} rightarrow R^{n}\
mu ( X) =frac{1}{m} x^{T} 1_{m}\
$$
Same insecurities here.
$$
sigma : R^{mtimes n}rightarrow R^{n}\
sigma ( X) =frac{1}{m}sqrt{left(sumlimits ^{n}_{j=0}left( X-1_{m} mu ( x)^{T}right)^{2}_{ij}right)_{j}}\
$$
Insecurities:
- I have to square each cell of the resulting matrix and sum the results in to a vector. I am using a fictional
i
index. How should I describe what i is? - I later have to square each element of the vector. Here I use
j
, but outside the summation. Again: how should I describe this?
Your insights are much appreciated as I would like to learn the right/conventional way of doing linear algebra and don't have access to a teacher. I am curious to know how would your solution would look like.
linear-algebra
add a comment |
I am doing a course on machine learning. In it I am asked to convert a matrix's columns to z-scores. It says:
Subtract the mean value of each feature from the dataset (columns of
X). After subtracting the mean, additionally scale (divide) the
feature values by their respective “standard deviations.”
This is not hard for me and I have written a little python function to this goal, but I was wondering what the vectorized version of this function would look like. So I set up some equations that I could then express in python, but I have done some unconventional things to achieve this and I would like to know what the conventional way would be.
Here is what I've got:
$$
z: R^{mtimes n}rightarrow R^{mtimes n}\
z( X) =left( X-1_{m} mu ( x)^{T}right) otimes 1_{m} sigma ( x)^{T}\
$$
Insecurities:
- The circle operator in this equation is the hadamard product. Does this even have an official operator? Should I describe what is meant with that operator? Or is there some way around it?
- I've added the function's mapping on top as is usual in certain programming languages like Haskell. I find this to be very handy in terms of doing linear algebra where you have to keep track of the dimensions of vectors and matrices. Is this common in expressing math as well?
Here are mu and sigma:
$$
mu :R^{mtimes n} rightarrow R^{n}\
mu ( X) =frac{1}{m} x^{T} 1_{m}\
$$
Same insecurities here.
$$
sigma : R^{mtimes n}rightarrow R^{n}\
sigma ( X) =frac{1}{m}sqrt{left(sumlimits ^{n}_{j=0}left( X-1_{m} mu ( x)^{T}right)^{2}_{ij}right)_{j}}\
$$
Insecurities:
- I have to square each cell of the resulting matrix and sum the results in to a vector. I am using a fictional
i
index. How should I describe what i is? - I later have to square each element of the vector. Here I use
j
, but outside the summation. Again: how should I describe this?
Your insights are much appreciated as I would like to learn the right/conventional way of doing linear algebra and don't have access to a teacher. I am curious to know how would your solution would look like.
linear-algebra
I am doing a course on machine learning. In it I am asked to convert a matrix's columns to z-scores. It says:
Subtract the mean value of each feature from the dataset (columns of
X). After subtracting the mean, additionally scale (divide) the
feature values by their respective “standard deviations.”
This is not hard for me and I have written a little python function to this goal, but I was wondering what the vectorized version of this function would look like. So I set up some equations that I could then express in python, but I have done some unconventional things to achieve this and I would like to know what the conventional way would be.
Here is what I've got:
$$
z: R^{mtimes n}rightarrow R^{mtimes n}\
z( X) =left( X-1_{m} mu ( x)^{T}right) otimes 1_{m} sigma ( x)^{T}\
$$
Insecurities:
- The circle operator in this equation is the hadamard product. Does this even have an official operator? Should I describe what is meant with that operator? Or is there some way around it?
- I've added the function's mapping on top as is usual in certain programming languages like Haskell. I find this to be very handy in terms of doing linear algebra where you have to keep track of the dimensions of vectors and matrices. Is this common in expressing math as well?
Here are mu and sigma:
$$
mu :R^{mtimes n} rightarrow R^{n}\
mu ( X) =frac{1}{m} x^{T} 1_{m}\
$$
Same insecurities here.
$$
sigma : R^{mtimes n}rightarrow R^{n}\
sigma ( X) =frac{1}{m}sqrt{left(sumlimits ^{n}_{j=0}left( X-1_{m} mu ( x)^{T}right)^{2}_{ij}right)_{j}}\
$$
Insecurities:
- I have to square each cell of the resulting matrix and sum the results in to a vector. I am using a fictional
i
index. How should I describe what i is? - I later have to square each element of the vector. Here I use
j
, but outside the summation. Again: how should I describe this?
Your insights are much appreciated as I would like to learn the right/conventional way of doing linear algebra and don't have access to a teacher. I am curious to know how would your solution would look like.
linear-algebra
linear-algebra
edited Dec 30 '18 at 16:05
asked Dec 30 '18 at 10:23
beginnersmind3
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I find your question very interesting. Hopefully we can chat about it in greater detail.
Is it the case that you feel comfortable programming a solution to this problem, but you are not confident is writing a mathematical exposition of the solution?
Or is it that you want to refactor your code to make it more in line with "standard" mathematical steps?
Cheers
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3056697%2fconvert-matrix-columns-to-z-scores-notation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I find your question very interesting. Hopefully we can chat about it in greater detail.
Is it the case that you feel comfortable programming a solution to this problem, but you are not confident is writing a mathematical exposition of the solution?
Or is it that you want to refactor your code to make it more in line with "standard" mathematical steps?
Cheers
New contributor
add a comment |
I find your question very interesting. Hopefully we can chat about it in greater detail.
Is it the case that you feel comfortable programming a solution to this problem, but you are not confident is writing a mathematical exposition of the solution?
Or is it that you want to refactor your code to make it more in line with "standard" mathematical steps?
Cheers
New contributor
add a comment |
I find your question very interesting. Hopefully we can chat about it in greater detail.
Is it the case that you feel comfortable programming a solution to this problem, but you are not confident is writing a mathematical exposition of the solution?
Or is it that you want to refactor your code to make it more in line with "standard" mathematical steps?
Cheers
New contributor
I find your question very interesting. Hopefully we can chat about it in greater detail.
Is it the case that you feel comfortable programming a solution to this problem, but you are not confident is writing a mathematical exposition of the solution?
Or is it that you want to refactor your code to make it more in line with "standard" mathematical steps?
Cheers
New contributor
New contributor
answered Jan 3 at 23:47
Richard
112
112
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3056697%2fconvert-matrix-columns-to-z-scores-notation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown