Data Analysis

Combinatorics problem

Posted on
  1. You are given a ten piece box of chocolate truffles. You know based on the label that six of the pieces have an orange cream filling and four of the pieces have a coconut filling. If you were to eat four pieces in a row, what is the probability that the first two pieces you eat have an orange cream filling and the last two have a coconut filling?

(given, O = orange, C = coconut) :

P(OOCC)

= P(1st is orange) * P(2nd is orange) * P(3rd is coconut) * P (4th is coconut)

= 6/10 * 5/9 * 4/8 * 3/7

= .6 * .556 * .5 * .429

= .0716

Follow-up question: If you were given an identical box of chocolates and again eat four pieces in a row, what is the probability that exactly two contain coconut filling?

  • Step 1 involves a combinatorics problem of 4 choose 2 to determine how many combinations of oranges and coconuts we can obtain given 4 pulls from the box :

= 4C2

= 4!/ (2! * (4-2)!)

= 24 / (2 * 2)

= 6

This is equivalent to the following six combinations:

CCOO, COCO, COOC, OCCO, OCOC, OOCC

  • Step 2. In the first question above, we learned that the probability of pulling exactly 2 coconuts in 4 pulls from the box is the same at pulling exactly 2 oranges as well and we can see that the probability is the same for all 6 combinations of Os and Cs.

Therefore, the probability of pulling exactly 2 coconuts

=  4C2 [see step 1 above] * .0716

=  6 * .0716

=  .4296

Digital Marketing

Are all my Digital Assets Secure when a key person leaves my organization?

Posted on

If you lost access to your business emails at this moment, what shape would your business be in? In the digital world, email accounts and passwords are now the “keys” to your business kingdom. Share them sparingly and covet them fiercely.

Do not have your team sign up for vital online services using their individual emails. The business manager’s email, say freddie@acme.com, may seem adequate and safe, but it is not. Most likely, only Freddie has access to that email and therefore all the business-related digital properties and services are tied to it. Instead, maintain a generic company email account and password for Internet services which can be accessed by several people by using a service such as LastPass.

For company-wide use, create something like web@acme.com to access your vital online services such as website hosting and merchant accounts. If Freddie the business manager decides to leave the company, perhaps in a huff, all you have to do is change one password and your business’s online accounts are secure. And please make your passwords non-trivial. Use an app like Norton’s free Password Generator to create tough-to-crack passwords. Don’t worry, LastPass will manage all the wacky passwords for you.

If your company is large, you can create several categorical email accounts like webDev@acme.com,  webAnalytics@acme.com, and webFinance@acme.com depending on departmental responsibilities. In this scenario, each password should be different across functional areas.

You get the picture. No matter what scheme you come up with to keep your digital business organized, make sure your emails and passwords are current, secure, and backed up, else you may face days of unnecessary fear and dread when Freddie the business manager decides to quit his job to work for the competition or join a rock band.

As a modern-day King Richard might cry at such a predicament, “My Kingdom for all my business-related email passwords!”

Fare thee well.

Data Analysis

U.S. Healthcare Associated Infections ( HAIs ) using CDC public data

Posted on

I just finished my @CDCgov data story about Healthcare Associated Infections ( #HAIs ) using D3. These infections are particularly nasty as they are antibiotic-resistant. I’ve created an interactive map of the U.S. with the total number of infections per state and the rate of infection per 1000 people for the latest available year, 2014. If CDC funding continues to be cut, it is unknown when the next HAI updates will be made.

Check it out here: http://www.peterbakke.com/bits/cdc-hai/

Image: CDC
Data Analysis

Excel and .csv lesson learned… Includes painful waste of time, unfortunately.

Posted on

I found out that when you export data in .csv format from #Excel make sure you don’t have a trailing space after any column names. They are exported as “col_name ” with the space AND quotes. Beware when using them to index your array! They will fail. Simply delete any hidden spaces in your column names before exporting. Please. For your own sanity. #DataAnalytics #ERROR #painful lesson.

Peter Bakke DOH!

Data Analysis

Debugging Javascript – one useful tool

Posted on

Here’s an idea for displaying those pesky ephemeral variables that come and go like ghosts in JavaScript. Check this out. I
want to know if I’m reading in a CSV file properly or not. You can use for any variable / array / object.

<script>

// Read in a .csv file
d3.csv(“../datafile.csv”, function(someData) {
debugMe(someData);

});

function debugMe(whateverData) {

// ‘Sum Ages’ is a variable in row zero of passed var ‘whateverData’
document.getElementById(“debug”).innerHTML = “Debug: ” + whateverData[0][‘Sum Ages’].toString()
}

</script>

<p id=”debug”></p>

Data Analysis

Python Immutable strings, integers, booleans

Posted on

In Python, STRINGS, INTS, BOOLs etc. are IMMUTABLE… meaning, for example, that you cannot convert a df column that is a string to a column that is int.  However,  you can ASSIGN the values (objects) to another variable or create a new instance of that column in another dataframe   … or use .astype(int) to perform an intermediate computation.

python-logo-Pete-Bakke

Data Analysis

Local Host Error .. Closing Windows CMD window = not good!

Posted on

FYI all users of Windows. I discovered that my local web server stopped working when I closed my Windows CMD window. I use the following command line to start up a local web server: python -m SimpleHTTPServer.

Makes sense, I suppose, that the web server craps out when the CMD window is closed, but it took moi quite a while to figure out why my local web-served data visualization file worked one minute and I got an error the next minute (http://localhost:8000/basic_charts.html Error message: This site can’t be reached … localhost refused to connect ).

Reason: I had closed the Windows CMD window somehow, somewhere along the way!  Newbie Noob error. Oh, well. Still learning!newbie here - Peter Bakke

Moi

Do the TWIST 

Posted on
 Some of my favorite movie plot twists (I don’t want to spoil any films you may not have seen, so read with care):

North by Northwest: Grace Kelly is actually an FBI informant who is found out by bad guys (James Mason and Martin Landau). Easter egg, in the shooting scene at the Mt. Rushmore restaurant, watch the young boy in the background cover his ears just before the gunfire occurs. Priceless.

Usual Suspects: Limping runt ends up being top dog.

Marathon Man: Diamonds thrown away at end.

Spellbound: Gregory Peck killed a man. But, he didn’t do it. But, he did do it. But, he didn’t do it.

Treasure of the Sierra Madre: Gold dust blows away in wind storm at finale.

Zulu: Final scene – you think 20,000 Zulu warriors are amassing for the coup de grace, but they pay their respects to the few remaining British soldiers and leave.

Charade: 1) Cary Grant is actually a government agent. 2) Hum-drum belongings contain an envelope with 3 stamps worth $250 thousand.

The List of Adrian Messanger: 1) Lots of disguised actors is loads of fun – Frank Sinatra, Robert Mitchum, Kirk Douglas, Tony Curtis, and Burt Lancaster. 2) Final scene of a fox hunt: George C. Scott outwits Kirk Douglas – it is Douglas, while escaping, who gets impaled on tines of repositioned farm equipment.

Sixth Sense: Bruce Willis is a dead man walking.

Bedford Incident: After Navy Captain (Richard Widmark) destroys a Soviet submarine with a tactical nuke there are a few stunned seconds of silence. Then the sonarman cries out: “Incoming torpedoes!” The ship has no defenses and everyone is doomed. No winners here. The look exchanged between Widmark and Sidney Potier when they know they are about to die is chilling and one of the greatest scenes in film, IMHO.

Failsafe: Quid pro quo for blasting Moscow to eternity, President Henry Fonda gives the order to nuke New York, even though he knows his wife is there.

A Few Good Men: One of the Marines on trial did not actually hear the order for “code red” from an officer – he heard it from his Marine friend who told him about it. Devastating to the defense, it sets up a great scene between Tome Cruise and Demi Moore (“the galactically stupid”). Don’t get me wrong, I love Demi Moore in this movie – nobody ever looked so good in Navy dress whites.

12 Monkeys: Too many twists to enumerate. But here’s one: Madeline Stowe thinks everything falls into place after she makes a phone call alone in Times Square. But when she chats with Bruce Willis about it afterward, he is able to repeat word-for-word what she said in the phone conversation. He has heard a recording of the conversation (from the future) – Gotcha!

Dr. Strangelove: All the thermonuclear explosions at the ending, starting with the one in the War room. BTW (Easter egg), towards the end of the movie, watch the actor, Peter Bull, in the background breaking up laughing as actor Peter Sellers, as Dr. Stranglove, bites his own hand, trying to prevent his own arm from doing a Nazi salute.

Uncategorized

Jerome Davis : World Traveler Promotes tours for Peace

Posted on

By Betty Knosler
Lake-Sumter Sentinel
Tuesday, January 22, 1963

CLERMONT – Sociologist, educator, world traveler, (war correpondent – Ed.), and lecturer would only begin to describe Dr. Jerome Dwight Davis, winter visitor to Clermont.

Dr. Davis, born in Kyoto, Japan, of Congregationalist missionaries (Father: Jerome Dean Davis – Ed.) near the turn of the century, has also been the author of over 25 books and an international YMCA representative.

While an Oberlin College student, he decided that, although he would not enter the missionary field as did his father, who founded the largest Christian University in Japan, he would devote his life to helping people everywhere with no thought of gain.

Still a student at Union Theological Seminary, he became secretary to Sir Wilfred Grenfell as he built hospitals, schools, and churches throughout Labrador and the Maritime provinces of Canada.

DOING MOST of their traveling by small ship, they were aground three times, on fire once, lost an anchor and were also hit by a huge iceberg.

Using axes to free stateroom doors and then to free the ship from the iceberg, they continues on course.

From 1916 to 1918, at the request of Dr. John R. Mott, world head of the YMCA, Davis represented the YMCA in Russia. Beginning with prisoner of war camps for German and Austrian prisoners, he established medical, educational, religious, recreational and self-governing committees in 29 prisoner of war camps.

The improving of conditions in the POW camps eventually led to the establishment of the first YMCA for Russian soldiers in Russia. This work was accomplished while the Tsar was still in power.

DR. DAVIS, who has seen the evils of Communism through his many trips to Russia, is bitterly opposes to the Communist doctrine, and believes that the only hope of the world lies in the success of the United Nations and a genuine effort for peace.

Following World War I, he taught at Dartmouth and in the Yale University Divinity School. It was during his Yale period that he became president of the American Federation of Teachers for three years and was also president of the Eastern Sociological Society.

Dr. Davis was chairman of the legislative commission on Jails for the state of Connecticut for 12 years, during which time many reforms were instituted in the penal system.

HE ALSO founded the religion and labor foundation, now located in Washington, which was instrumental in focusing attention on the wrongs of the 12-hour day and the seven-day work week. This was abolished eight years after the foundation’s establishment.

Representing the YMCA again, from 1940 to 1943, Dr. Davis was director of YMCA work in the prisoner of war camps in all of Canada.

(In 1944, Dr. Davis was a war correspondent for the Toronto Star, stationed in Moscow – Ed.)

For the last few years Dr. Davis has devoted his time to lecturing, writing books and heading international good will tour groups each summer. These groups are composed of teachers, ministers, doctors and other professional people.

This summer, one group will go to West Africa and the Middle East and a second group will go to the Scandinavian countries, Russia, Turkestan and France.

The tours are sponsored by Promoting Enduring Peace, Inc., of which Dr. Davis is executive director. He believes that person to person contact wins friendship for the American in foreign lands.

The only way we can change the kind of world we are in is by slow, constructive change, not revolution.

On these tours, they try to prove to the people of the world that the U. S. has more to offer and can be of more assistance than can any other country or countries.

DR. DAVIS would welcome inquiries sent to either 489 Ocean Ave., West Haven, Conn., or 2025 Sunset Lane, Clermont, from anyone interested in these tours.

The latest book of Dr. Davis will be published by Citadel Press in cloth and paper editions in June. The book “World Leaders I have Known” includes stories on Sir Grenfell, Franklin D. Roosevelt, Harry Emerson Fosdick, Walter Reuther, Sidney Hillman, Djilas, who is now in a Yugoslavian prison, Kagawa of Japan and Ghandi of India.

(Text entered by Peter Bakke)

Data Analysis

Getting python.exe to run from any directory on my PC so I could use D3’s external data file load function

Posted on

The only way I could get python (python.exe) to run from any directory via from the command line was to set the SYSTEM variable PATH, *not* by changing the USER variable path. Arghhh. Took an hour of searching the Oracle (i.e., Google) to finally discover this.

Where I was headed was that I needed to steer to a local directory in the command line in order to start a local web server for using D3 …  http://localhost:8000/whatever.html. I started a local web server using  ‘python -m SimpleHTTPServer’.  Loading a local external file in D3, like:

d3.tsv("data.tsv", function(data) {
console.log(data[0].x);
});

requires a web server to be running (due to AJAX calls).

Unlike other frameworks / apps, D3 does *not* use the local machine’s OS file system to load files, it needs a web server. Who knew? Arghhh (redux).

Frustration Peter Bakke