Tuesday, July 25, 2023

ChatGPT and code generation: be careful

I've heard bold pronouncements that Large Language Models (LLMs), and ChatGPT in particular, will greatly speed up software development with all kinds of consequences. Most of these pronouncements seem to come from 'armchair generals' who are a long way from writing code. I'm going to chime in with my real-world experiences and give you a more realistic view.

D J Shin, CC BY-SA 3.0, via Wikimedia Commons

I've used ChatGPT to generate Python code to solve some small-scale problems. These are things like using an API or doing some simple statistical analysis or chart plotting. Recently, I've branched out to more complex problems, which is where its limitations become more obvious.

In my experience, ChatGPT is excellent for generating code for small problems. It might not solve the problem completely, but it will automate most of the boring pieces and give you a good platform to get going. The code it generates is good with some exceptions. It doesn't generate doc strings for functions, it's light on comments, and it doesn't always follow PEP8 layout, but it does lay out its code clearly and it uses functions well. The supporting documentation it creates is great, in fact, it's much better than the documentation most humans produce. 

For larger problems, it falls down, sometimes badly. I gave it a brief to create code to demonstrate the Central Limit Theorem (CLT) using Bokeh charts with several underlying distributions. Part of the brief it did well and it clearly understood how to demonstrate the CLT, but there were problems I had to fix. It generated code for an out-of-date version of Bokeh which required some digging and coding to fix; this could have been cured by simply adding comments about the versions of libraries it was using. It also chose some wrong variable names (it used the reverse of what I would have chosen). More importantly, it did some weird and wrong things with the data at the end of the process, I spotted its mistake in a few minutes and spent 30 minutes rewriting code to correct it. I had similar problems with other longer briefs I gave ChatGPT.

Obviously, the problems I encountered could have been due to incomplete or ambiguous briefs. A solution might have been to spend time refining my brief until it gave me the code I wanted, but that may have taken some time. Which would have been faster, writing new detailed briefs or fixing code that was only a bit wrong? 

More worryingly,  I spotted what was wrong because I knew the output I expected. What if this had been a new problem where I didn't know what the result should look like?

After playing around with ChatGPT for a while, here are my takeaways:

  • ChatGPT code generation is about the level of a good junior programmer.
  • You should use it as a productivity boost to automate the boring bits of coding, a jump start.
  • Never trust the code and always check what it's doing. Don't use it when you don't know what the result should look like.

Obviously, this is ChatGPT today and the technology isn't standing still. I would expect future versions to improve on commenting etc. What will be harder is the brief. The problem here isn't the LLM, it's with the person writing the brief. English is a very imperfect language for detailed specifications which means we're stuck with ambiguities. I might write what I think is the perfect brief, only to find out I've been imprecise or ambiguous. Technology change is unlikely to fix this problem in the short term.

Of course, other industries have gone through similar disruptive changes in the past. The advent of CAD/CAM didn't mean the end of factory work, it raised productivity at the expense of requiring a higher skill set. The workers with the higher skillset gained, and those with a lesser skillset lost out.

In my view, here's how things are likely to evolve. LLMs will become standard tools to aid data scientists and software developers. They'll be productivity boosters that will require a high skill set to use. The people most negatively impacted will be junior staff or the less skilled, the people who gain the most will be those with experience and a high skill level.

Thursday, May 18, 2023

Isolated track vocals; hear who really can sing

Hear just the singer

Modern signal processing and machine learning can do some incredible things, one of which is to take a song and isolate just the singer's voice. It's called isolated track vocals and it sounds a bit like an a cappella version of a song. It's a bit weird sometimes, but it lets you hear who's a great singer and who just isn't. Here are some notable vocals I thought you might like.

Freddie Mercury - Queen - We Are The Champions

This man could sing. There are lots of Queen songs that have gone through the isolated track vocals process, but I've just chosen one for you to listen to. As you might expect, Freddie Mercury is outstanding.

Nirvana - Smells Like Teen Spirit


The Beatles - We Can Work It Out


The Clash - London Calling

The singing here isn't as good as on some of the other songs, but there's 100% commitment and passion.


Listen to more

You can hear more isolated track vocals on YouTube or SoundCloud, just search for 'isolated track vocals'.

Monday, May 15, 2023

The bad boy of bar charts: William Playfair

A spy, a scoundrel, and a scholar

William Playfair was all three. He led an extraordinary life at the heart of many of the great events of the 18th and 19th centuries, mostly in morally dubious roles. Among all the intrigue, scandal, and indebtedness, he found time to invent the bar and pie charts, and make pioneering use of line charts. As we'll see, he was quite a character.

Playfair the scoundrel

Playfair's lifetime (1759-1823) contained some momentous events:

  • The development of the steam engine
  • The French revolution
  • American independence and the establishment of a new US government
  • The introduction of paper money

and in different ways, some of them fraudulent, Playfair played a role.

He was born in 1759 in Dundee, Scotland, and due to his father's death, he was apprenticed to the inventor of the threshing machine at age 13. From there, he went to work for one of the leading producers of steam engines, James Watt. So far, this is standard "pull yourself up by your bootstraps with family connections" stuff. Things started to go awry when he moved to London in 1782 where he set up a silversmith company and was granted several patents. The business failed with some hints of impropriety, which was a taste of things to come.

In 1787, he moved to Paris where he sold steam engines and was a dealmaking middleman. This meant he knew the leading figures of French society. He was present at the storming of the Bastille in 1789 and may have had some mid-level command role there. During the revolution, he continued to do deals and work with the French elite, but he made enemies along the way. As the reign of terror got going, Playfair fled the country.

Before fleeing, Playfair had a hand in the Scioto Company, a company formed to sell land to settlers in the Ohio Valley in the new United States. The idea of setting up in a new land was of course attractive to the French elite who could see how the revolution was going.  The trouble was, the land was in territory controlled by Native Americans and it was also undeveloped and remote. In other words, completely unsuited for the French Bourgeoisie who were buying the land for a fresh start. The scheme even ended up entangling George Washington. It all ended badly and the US government had to step in to clean up the mess. This is considered to be the first major scandal in US history.

By 1793, Playfair was back in London where he helped formed a security bank, similar to institutions he'd been involved with in France.  Of course, it failed with allegations of fraud.

Playfair had always been a good writer and good at explaining data. He'd produced several books and pamphlets, and by the mid-1790s, he was trying to earn a living at it. But things didn't go too well, and he ended up imprisoned for debt in the notorious Fleet Prison (released in 1802). He tried to write his way out of debt, and notably, some of his most influential books were written while in prison.

There were no official government spying agencies at the time, but the British government quite happily paid for freelancers to do it, which may be an early example of "plausible deniability". Playfair was one such freelance secret agent. He discovered the secrets of the breakthrough French semaphore system while living in Frankfurt and handed them over to the British government in the mid-1790s. He was also the mastermind behind an audacious scheme to bring down the French government through massive counterfeiting and inflation.  The idea was simple, counterfeit French "paper money" and flood the country with high-quality fakes, stoking inflation and bringing down the currency and hence the government. The scheme may have worked as the currency collapsed and Napoleon took power in a coup in 1799, though Napoleon was worse for the British government than what had existed before.

By 1816, Playfair was broke again. What better way to get money quickly than a spot of blackmail targeted against Lord Archibald Douglas, the wealthiest man in Scotland? If you can dispute his parentage (and therefore his rights to his fortune), you can make a killing. Like many of Playfair's other schemes, this one failed too.

Bar charts and pie charts

Playfair invented the bar chart in his 1786 book, "Commercial and Political Atlas". He wanted to show Scottish imports and exports but didn't have enough data for a time series plot. All he had was imports and exports from different countries and he wanted to display the information in a way that would help his book sell. Here it is, the first bar chart. It shows imports and exports to and from Scotland by country.

This was such a new concept that Playfair had to provide instructions on how to read it.

Playfair's landmark book was "The Statistical Breviary, Shewing on a Principle Entirely New, The Resources of Every State and Kingdom in Europe, Illustrated with Stained Copper-Plate Charts Representing the Physical Powers of Each Distinct Nation with Ease and Perspicuity", which was a statistical economic review of Europe. This book had what may be the first pie chart.


This chart shows how much of the Turkish Empire was geographically European and how much African. Playfair repeated the same type of visualization in 1805's "Statistical Account of the United States of America", but this time in color:

He was an early pioneer of line charts too, as this famous economic chart of England's balance of payments deficits and surpluses shows (again, from 1786's "Commercial and Political Atlas").

Playfair on TV

To my knowledge, there's never been a TV depiction of Playfair, which seems a shame. His life has most of the ingredients for a costume drama mini-series.  There would be British Lords and Ladies in period costumes, French aristocrats in all their finery, political intrigue and terror, the guillotine, espionage, fraud on an epic scale (even allowing George Washington to make an appearance), counterfeiting, stream engines and rolling mills (as things to be sold and as things to make counterfeit money), prison, and of course, writing. It could be a kind of Bridgerton for nerds.

Reading more

Surprisingly, William Playfair is a bit niche and there's not that much about him and his works.

The best source of information is "PLAYFAIR: The True Story of the British Secret Agent Who Changed How We See the World" by Bruce Berkowitz. The book digs into Playfair's wild history and is the best source of information on the Scioto Company scandal and counterfeiting.

Here are some other sources you might find useful (note that most of them reference Bruce Berkowitz's book).

Tuesday, May 9, 2023

The Coronation and visions of the future

The 1950s version of the future

I watched the Coronation last weekend and it reminded me of some childhood experiences I had in Britain. I remember finding and reading old books from around the time of the previous Coronation that talked about the future. I read these books decades after they were published and it was obvious their predictions were way off course, but why they were so wrong is informative. Of course, the books I read were from a British perspective, this was similar in some ways to the American vision of the time, but more black and white.

Hovercraft everywhere

Hovercraft are a British invention and first saw use in the UK in the late 1950s. Of course, the books all had (black and white) photos of hovercraft racing across the waves. The prose was breathless and it was plain the authors felt the future was both air-cushioned and British-led. Uniformly, the authors predicted widespread and worldwide adoption. 

(The National Archives UK, No restrictions, via Wikimedia Commons)

By the time I read these books, the problems of hovercraft were becoming apparent; hovercraft as a commercial means of travel were in full retreat. Some of the limitations of hovercraft were well-known in the late 1950s, but none of the books mentioned them. Even as a child, I felt disappointed in the writers' naive optimism, they should have been able to see the flaws in the technology. 

Transport

In the future, if we weren't traveling in hovercraft, then we were traveling in cars; no one ever seems to use public transport of any kind. There didn't seem to be a British version of a future car, it all seemed to have been imported from America, including the images. Maybe the writers were already justly cynical about the future of the British car industry.

The Conquest of Space

All the books forecasted a space-faring future and all of them had people living on the moon and in space by the year 2000. In this case, the vision wasn't imported, there was a definite British spin on the space future and the images were home-grown too. There was a belief that Britain would have its own space program, including lunar settlements, space stations, and solar system exploration. All the text and images assumed that these would be British missions; other countries might have programs too, but Britain would have its own, independent, space activities.

The home

Like American versions of the future, British versions of the future were deeply conservative. The family would be a husband and wife and two children, with very traditional gender roles. The husband would travel to work in his futuristic car, the wife would prepare meals in a futuristic kitchen, and the children would play board games in front of a giant TV screen. The kitchen was full of futuristic gadgets to prepare meals in minutes, but the interfaces for these gadgets were always knobs, dials, and switches, and the gadgets were always metal with an enamel finish, no plastics in the future. The TV doubled as a videophone and there were illustrations of the family talking to their relatives in one of the white British ex-colonies.

The future clothes were largely 1950s clothes, the "clothing is silver in the future" idea was a cliche even then.

Society and politics

Oddly, there were very few predictions about society changing and the writers all missed what should have been obvious trends.

Immigration into the UK had happened for centuries with group after group arriving and settling. If the waves of immigration were large enough, they had an impact on British culture, including food. All of the writers seemed to assume that there would be no mass immigration and no changes in diet as a result (in the future, everyone ate 1950s food). Although it would be hard to guess what the immigrant groups would be, it should have been obvious that there would be immigration and that it would change Britain. This is an unforgivable miss and shows the futurists were naive. 

None of the writers really dealt with the ongoing consequences of the end of Empire. After independence, many countries continued to do business with Britain, but as colonial ties weakened, they started to do business elsewhere, and as a result, British exports dropped and so did employment. The writers had a sunny optimism that things would continue as before. None of them predicted that the ex-colonies could rise and challenge Britain in any way. The same assumption of British superiority ran through the writing.

Of course, the main assumption behind all of the writing, including the fiction, was that the future was heterosexual, middle-class, and white. The class system was very much intact and very much in its 1950s form. People knew their place and the social hierarchy was solid. Even as a child, I thought this was a suffocating view of the future.

Fiction: Arthur C. Clarke and Dan Dare

I have mixed feelings about the British science fiction of the time. It was naively optimistic, but that was part of its charm and appeal.

The leading science fiction comic strip was "Dan Dare: Pilot of the Future", about a future British space pilot who had adventures battling nefarious aliens across the galaxy. Dan was always the good guy and the aliens were always bad, once again, very black and white. Dan's role was to preserve order for humanity (or Britain). It was Britain as a galactic policeman and force for good. Even today, Dan Dare has a following.

Arthur C. Clarke produced a lot of fiction that was very rooted in British culture of the time and once again was very conservative about society. However, he was sunnily optimistic that somehow things would work out for the best. Ingenuity and bravery would always save the day. 

Optimism and conservatism

The two threads running through the different books I read were optimism and conservatism. The optimism was naive but exciting; the authors all believed the future would be a much better place. The conservatism was constraining though and meant they missed big changes they should have seen.

Perhaps optimism and conservatism were a reflection of the times; Britain was still a global power with interests around the world, it had just emerged victorious from World War II but paid a heavy price. The writers were living in a country that was in a relatively strong position relative to others, even other European nations. The rise of Japan and South Korea was still in the future and China was just emerging from its civil war. Maybe British people wanted to believe in a utopian British future and were willing to buy and keep optimistic books that told them comforting things.

What it says

Everyone is wrong about the future, but how they're wrong tells us something about the attitudes and beliefs of the time. These British books of the 1950s forecasted a technologically advanced world with Britain at its core; the world they painted was one where 1950s British values and cultural norms would remain globally dominant. It almost feels as if the writers deliberately built a future in which those values could triumph. 

And what of today?

There's a new King and there will be new books forecasting the future. There's plenty written now about how technology may advance and more writing on how society may change. The difference from the 1950s is the lack of consensus on what society's future may be. I see two opposite trends in fiction and in futurology: pessimism and optimism.

The fiction of choice for pessimism is dystopian. The world as we know it comes to an end through war or zombies or a virus, leaving people fighting for survival. The dominant themes are self-reliance and distrust of strangers; people who are different from you are the enemy.

The fiction of choice for optimism is Star Trek or Dr. Who. The future is fundamentally a decent place with the occasional existential crisis. People work together and strangers are mostly good people who could be your friends. 

Perhaps this split says a lot about today's society. We create futures where the values we believe in can thrive.

Monday, May 1, 2023

Coworking spaces: the challenge for company loyalty

Coworking spaces are something new

Over the last year, I've spent a couple of weeks working in coworking spaces in London and New York. After spending the last week at a coworking space, I've come away thinking that these spaces represent a profound change for workers and a challenge to how companies relate to their remote staff.  

Of course, the rental office space market isn't new; it goes back decades in different countries around the world. What is new is the price, flexibility, and type of workspace. The lowest price tier offers you space in an open-plan office with good wifi, coffee, and maybe other facilities thrown in. The low price, high density, and open-plan nature of the office are what's driving the change.

(A coworking space.)

My experiences

Three things stood out for me in my coworking experience: diversity, energy, and business focus.

I was surprised at the diversity of people I met, they were a much more diverse crowd than any company I've been a part of. By diversity, I mean many things. Obviously, racial and national origin diversity; the people I met were from many different countries with a range of racial backgrounds. But also job roles, I met artists, digital marketers, sales reps, planners, and more. The stereotype is that coworking spaces are full of coders, but that hasn't been my experience. The types of business were wildly different too, everything from infrastructure to car leasing, to contract marketing, to diversity hiring. I heard some really engaging stories that have caused me to think, more so than happens from day-to-day outside of coworking spaces.

The energy was high at all times. Everyone seemed to have a sense of purpose and focus on what they were doing plus the drive to work at it. That's probably a selection bias as these spaces tend to be full of young companies and people working for themselves, but even so, it was good to experience.

Despite the wide range of businesses, everyone was focused on their customers and what they need to do to sell to them. Everyone was keenly aware of the need to make money and the mantra "everyone is in sales" seemed very true for them.

Notably, not all career stages and ages were equally represented. I saw very few people at the start of their careers, the youngest tended to be a few years out of college and on their second or third job. At the other end, I saw very few people who looked to be in their 50s and no one who looked close to retirement. On the whole, people tended to be late 20s or early 30s.

Where things get interesting are the events and services these coworking spaces provide. Many spaces offer a barista and some serve beer and wine after 5pm. I've seen wine tastings and other social events. Some places have one-off business services like professional headshots and so on. These are exactly the types of services and events companies offer to their on-site staff, and this is where the challenge comes.

The coworking challenge

All companies try to promote loyalty, which requires staff proximity and communication. Loyalty helps with productivity, goal alignment, and stability; a loyal workforce will stay with a company during tough times. Social programs, 1:1 meetings, and group meetings all help with proximity, and newsletters and Slack, etc. help with communications, but these things are much harder with a remote workforce. 

Look at what happens in a coworking space. You get proximity because others share the space with you and the coworking space runs social events to encourage mixing (and loyalty). You get communications too, many coworking spaces send out email newsletters, and so on.

Now imagine you're a remote employee working out of a coworking space. Imagine it's 3pm on a Thursday and your company is running a social event over Zoom. At the same time, your coworking space is offering an in-person social event with all the people you meet every day in the office with beer and wine. Which event would you go to?

What about lunches? Some companies offer to pay for remote employees' lunches on special occasions, but the employee has to order their lunch and submit an expense claim (effort). By contrast, if a coworking space offers a free lunch, all the employee has to do is turn up and eat. Which would you prefer?

As a remote employee, would you be more loyal to your coworking space or your employer?

What this means

There is a form of loyalty competition between the company a worker works for and the coworking space the worker uses. The coworking space has the upper hand in the way the loyalty game is mostly played today. But there are other ways to generate loyalty, for example, promotions and pay rises, training and staff development, conferences, and so on; things which add lasting value to an employee.

Companies need to realize that the remote experience is different, especially if someone is in a coworking space. If companies want loyal staff, they have to offer something meaningful because coworking spaces are using loyalty levers too and they have the decisive physical advantage.

Sunday, April 16, 2023

You can be too clever with visualizations

Front page of the paper

I saw this visualization on Friday, April 14th 2023, on the front page of the New York Times. It was an illustration for an article about increasing the use of electricity to tackle climate change in the United States. Unfortunately, the visualization is at best confusing. You can read the full article here: https://www.nytimes.com/interactive/2023/04/14/climate/electric-car-heater-everything.html

(New York Times 14th April, 2023)

The message

The message the article was trying to convey was a simple one: it was a modeling exercise for a more electrified US with lower energy consumption. The animations in the article made clear where electricity use would need to grow and roughly by how much.

Why the presentation is bad

The visualization is a sort of pie chart. In most cases, pie charts are very bad data visualizations, and this article compounds the problem by using a non-standard form. 

Just looking at the charts, can you tell me what the percentages are for Transportation, Industrial, etc. now and in the "electrified future"? Can you tell me what's growing?

The article makes plain the modeling work is for reduced energy consumption. Looking at the two charts, can you tell me what the reduction is and over what timescale it occurs?

I could go on, but it's easy to see for yourself what's wrong. Look at the charts and tell me what you take away from them.

The article contains animations that make the message clearer, but even so, it took me a lot of work to figure out what was going on. This takes us to the major visualization sin here: the level of effort to understand what's going on is too high.

What's the takeaway?

You can get too clever with visualizations. Just because you can, doesn't mean you should. Keep things simple and easy to understand.

Sunday, April 2, 2023

I'm curious if you want to buy from me

Over the last few months, I’ve been getting sales prospecting emails that all have the same keyword: “curious”. Here are a few (anonymized) examples:

…and was curious to learn more about your…

…but curious what time to action looks like…

Just curious to check on my previous email …

…but curious if you have any thoughts on the above…

I'm curious if you run into challenges maintaining…

I was curious to learn about your current…

I am curious to see if you are looking…

(A curious cat - Dimitri Houtteman, CC0, via Wikimedia Commons)

I ignore all these emails. Why? Because they’re poor prospecting.

Here’s the reality. These emails are being sent by BDRs or SDRs and they’re prospecting for business. This is a fine, even noble thing to do. But the sender isn’t curious and they’re not interested in my views; the sender wants to know if I’m a prospect. 

These are poor prospecting emails for several reasons. First off, the word “curious” is now a tip-off that the email is prospecting and so destined for quick deletion (I rarely get passed the word curious). Secondly, my email provider is getting smarter and it’s now diverting “curious” emails to my spam folder, I found half of these examples there. Unfortunately for the senders, “curious” is a relatively uncommon word so spam filters easily learn to filter it out.

I’m very busy. I don’t have time to read through a long prospecting email. If the first word I come across is a trigger (e.g., “curious”) I delete the email. The prospecting emails I read are ones that address a real business issue and get to the point quickly. Some really good prospecting emails have mentioned good quality case studies I’m interested in and made it easy for me to read them (I’m not filling in a long registration form and I’m not giving you my phone number).

(There seems to be a broken selling model here. I don't have time to meet with every salesperson who contacts me. You need to establish value first. So provide me with a low-effort way to see if I'm interested then let's escalate commitment. It's a bit like a romantic relationship; very few people get married after a first date.)

I’m sure there must be a BDR or SDR course out there that tells people to use words like “curious” or “interested”. Perhaps in the past, it may even have worked. I’m not convinced it does now. It’s time to move on.

Friday, March 31, 2023

How to improve your business writing

The need for better business writing

Let's face it, a lot of business writing is just bad; you wouldn't read it if you didn't have to. You're left wondering whether the person who wrote it hated writing it as much as you hated reading it.

The problems are well-known: turgid prose, needless complexity, cryptic meanings, pseudo-academic obscurity, and so on.

Annoyingly, books on business writing aren't much help for improving business writing. They explain the difference between an abstract and an introduction and they talk about the need for structure, but that's about it. Style guides are of little use too; they give you advice on how to abbreviate American states but don't help you make your reports readable.


A better type of writing

But business writing doesn't have to be like this. What if I told you there was a style of writing that people:

  • voluntarily read 
  • described as "sparkling", "insightful", or "game-changing" 
  • won Nobel prizes for.

Wouldn't you want to know what it was?

Of course, I'm talking about fiction writing.

Before you object, let me tell you something: fiction writers do a lot of things that business writers should do. They do it so well, they make a living from it. 

Fiction writing basics

Let's look at the basics of what fiction writers do.

Write for their audience. Most, if not all writers know who their target audience is and what they want. Thriller writers, literary fiction writers, and romance writers tailor their writing for the people who buy their books. If they don't, they won't get published and won't get paid. The first lesson for business writers: know your audience and what they want to hear.

Have a good story to tell. No one likes a boring story. Some fiction writers can take a dull situation and turn it into something amazing through insight and storytelling; they can make the ordinary exciting. The second lesson for business writers is: tell your audience an engaging story.

Organize your story. Lots of business writing books tell you about paragraphs and structure, but fiction writing books go much further. There are all kinds of narrative structures available to you; you can tell a story in reverse chronological order, from different character perspectives, with different-length chapters, and so on. Of course, there's also the choice of point of view. Stories don't have to follow a linear time narrative and your business report doesn't have to be linear either. The third lesson for business writers is: use the appropriate organization to tell your story.

Use appropriate language. This is the part I'm saddest about. Fiction writers use all kinds of ways to make their stories engaging:

  • using the active voice rather than the passive voice
  • sentence length
    • use shorter sentences for action and longer sentences for thought
    • vary sentence length for variety
  • avoid using adverbs (Stephen King!)
  • use simple words rather than complex ones (unless the complex word makes a particular point)
  • remove unnecessary words
  • use alliteration, anaphora, tricolon, and other rhetorical techniques
  • ...and so on.

What was the last report that made you think? What was the last report that made you feel anything at all? What was the last report that used alliteration, anaphora, and tricolon crescens to persuade you? The fourth lesson for business writers is: be artful about the language you use to tell your story. 

What to read next

There are a lot of great books on writing fiction. Here are just a few I recommend.

  • Stephen King, On writing.
  • Ursula K. Le Guin. Steering the craft.

Ian Fleming wrote about writing. What he said has aged badly in many places, but his underlying message is clear: he wrote for his audience and he thought deeply about what they wanted. Here's the piece.

Sunday, March 19, 2023

Is it OK to lie in business for the right reason?

Can lying in business be OK?

A long time ago I was in a very difficult ethical position. The best thing to do for the business was to lie and mislead technical executive management, but it didn't sit right with me. My boss was more flexible, he did the misleading for me, and the result was the executives made the right decision. Listen to my story and tell me what you think was the right thing to do.


The situation

My company has previously bought exclusively from supplier X, but supplier X was having financial difficulties and had stopped innovating; their products were extremely expensive relative to the market. My company had just spent a large amount of money with X and our technical executive management was very committed to them, it was very apparent we were an "X shop". At the same time, the technology had changed and new entrants had come to the market offering faster and cheaper products. 

My team needed new hardware to generate network traffic. We tried the solution from X, but it just didn't give us anything like the performance we needed and was extremely expensive. We then tried a product from one of the new entrants which gave us the performance we needed (and more) and was much cheaper. In fact, performance was 10x faster and we had the test results to prove it. So my team wanted to buy from the new entrant.

The dilemma

My manager told me that if we told the truth that the new entrant was 10x faster than X and much cheaper, technical executive management wouldn't believe us and we would lose credibility, in fact, it's likely we would be told to go with technology from X even though it wasn't good enough. 

I wanted to educate technical executive management and show them what we'd found. My boss said that was a bad idea and we should spin a story technical executive management could accept.

What should we do?

What happened

My boss took the results and did some massaging. He told the technical executive team that while the new entrant wasn't as fast as company X, it was a lot cheaper and was a better fit for this particular project - he implied it would be a sacrifice for the team to go with the new entrant, but we would do it to save money. He reassured executive management that their prior decision to go with X was sound because the other projects were different. He presented a version of the results that hinted we needed more equipment from the new entrant than we would need from X, but it would still be cheaper overall.

We got permission to go with the new entrant. My boss told me that technical executive management had commented that the new entrant had really come a long way and that maybe in five years they would be as good as X.

Subsequent events

Within a year, supplier X hit bigger financial problems and was taken over. It stopped producing networking equipment completely. My employer moved off their hardware within two years and exclusively bought equipment from new market entrants. 

The story in the specialized press was that X had offered inferior and over-priced products for some time. When new entrants came into the market with faster and cheaper technology, X couldn't compete. X had been reliant on inertia and existing business relationships for sales, but of course, that came to an end eventually.

Technical executive management talked about how their decision to go with the new entrant for my project showed they were on top of things. However, company C-level leadership had changed and they wanted better technical decision-making, so the entirety of the technical executive management team changed. However, I was long gone by this point.

Sunk cost fallacy

This is an example of the sunk cost fallacy where people remain committed to something because of the amount of effort they've previously put into it, even though going with something new would be better. There are numerous examples in business and politics. 

In this case, technical executive management had invested a lot in supplier X, including their own credibility. Because of that investment, they weren't going to change suppliers easily, even though they "should".

Unfortunately, I've seen other examples of the sunk cost fallacy over the years, but never anything as bad as this. Organizational inertia is a real thing and it can be gut-wrenching to make changes. Sadly, the heralds of change are often punished and end up leaving because their message is uncomfortable; the nail that sticks up is the one that's hammered down.

What's the right thing to do?

Over the years, I've come to the conclusion that my boss made the right call in the circumstances. Yes, technical executive management was wrong, but they were deep into the sunk cost fallacy and weren't thinking rationally. There was no way they would have accepted our results, even though they were true. They needed a rationale that would enable them to cling to X while giving us permission to do something new, and my boss gave it to them. The best possible solution for the company was for technical executive management to realize how the market had shifted and change their buying behavior, but they just weren't ready to do so and it would have been career suicide for us to try.

Ultimately, it's not about doing what's right, it's about making the change you can.

What do you think?

Monday, January 9, 2023

The longest journeys in the world

How far can I go by boat, or by car, or by plane?

What are the longest journeys you could make by boat without crossing land, by land without crossing water, and by plane? The answers are a little surprising as we'll see. For comparison, the circumference of the earth is about 24,901 miles, so you'll get a sense of how far around the world you can go.

What's the longest distance I could sail in a straight line without crossing land?

Here's an image of the world using the typical Mercator projection. What would you say is the longest journey you could make over water in a straight line without crossing land?

(Strebe, CC BY-SA 3.0, via Wikimedia Commons)

What if I told you this was the longest straight line journey.

(Source: Reddit)

The journey is 19,940 miles, so nearly all the way around the world. It starts in Sonmiani, Pakistan and ends in the Karaginsky District, Russia.

The reason why this path looks so 'kinked' is because of distortions introduced by mapping a 3d object onto a 2d surface and of course by the Mercator projection. If you look at the path on a globe, it becomes more obvious it's a straight line. Here's a YouTube video that shows an animation of the path.

This path was originally found by a Reddit user (Patrick Anderson, AKA kepleronlyknows) and then proved by Rohan Chabukswar and Kushal Mukherjee. It's a great example of ctizen science.

What's the longest distance I could walk in a straight line without crossing water?

Rohan Chabukswar and Kushal Mukherjee found the answer in their paper, here it is.

This isn't that surprising and the curve should be no surprise either, this is just a grear circle that's entirely on land. It's about 7,000 miles long, so much shorter than the longest sailing. It goes from Sagres, Portugal to Jinjiang, Quanzhou, China

What's the longest plane journey?

The earth is round, so the furthest journey you could do is to the antipodes which is halfway round the world (12,450 miles). In reality, planes don't exactly follow great circles all the time, so we might expect even a journey to the antipodes to be a bit longer.

Here are the world's longest scheduled flights according to Upgraded Points:

RouteAirlineDistanceScheduled Flight Time
1. Singapore (SIN) to New York (JFK)
Singapore Airlines9,537 miles18 hours, 50 minutes
2. Singapore (SIN) to Newark (EWR)
Singapore Airlines9,523 miles18 hours, 45 minutes
3. Perth (PER) to London (LHR)Qantas9,010 miles17 hours, 15 minutes
4. Melbourne (MEL) to Dallas (DFW)Qantas8,992 miles17 hours 35 minutes
5. Auckland (AKL) to New York (JFK)
Air New Zealand8,828 miles17 hours, 50 minutes

At 9,537 miles, flights are not yet getting half way around the world.

What's the world's longest bus journey?

Would you believe London to Kolkata, a distance of 10,000 miles, or even London to Sydney? Wikipedia has an entry all about it. 

What's the world's longest train journey?

This one is easy, it seems like almost every pub quiz asks it. The longest single journey is of course the Trans-Siberian railway at 5,753 miles. The longest connecting journey goes from southern Portugal to Singapore and is around 11,653 miles.

What's the world's longest subway ride?

This was surprisingly difficult to find the answer to. It's line 6 of the Chongqing Rail Transit, which come in at 53 miles. As you might expect, it's a relatvely new subway line (2012) and is rather sleek and modern.

What's an isochrone map?

An isochrone map shows travel time from a point, for example, how long it takes to get from London to various other places. The screenshot below shows how far from Marble Arch you could go in an hour. You can play around with isochrone maps on this great website: https://app.traveltime.com/


How far might I travel in a year?

Depending on the state, the average American drives 14,263 miles per year (40 miles a day), which is over halfway round the world. If you wanted to go all the way around the world in a year, that would be about 70 miles a day.


Sunday, January 1, 2023

My advice to students looking for a job

I can't talk to you all

Every week, I get several contacts on LinkedIn from students looking for their first job in Data Science.  I'm very sympathetic, but I just don't have the time to speak to people individually. I do want to help though, which is why I put together this blog post. I'm going to tell you what hiring managers are looking for, the why behind the questions you might be asked, and what you can do to stand out as a candidate.

(Chiplanay, CC BY-SA 4.0, via Wikimedia Commons)

Baseline expectations

I don't expect new graduates to have industry knowledge and context, but I do expect them to have a basic toolkit of methods and to know when to apply them and when not to. In my view, the purpose of completing a postgraduate degree is to give someone that toolkit; I'm not going to hire a candidate who needs basic training when they've just completed a couple of years of study in the field.  

Having said that, I don't expect perfect answers, I've had people who've forgotten the word 'median' but could tell me what they mean and that's OK, everyone forgets things under pressure. I'm happy if people can tell me the principles even if they've forgotten the name of the method.

The goal of my interview process is to find candidates who'll be productive quickly. Your goal as a candidate is to convince me that you can get things done quickly, right, and well.

Classroom vs. the real world

In business, our problems are often poorly framed and ambiguous, it's very rare that problems look like classroom problems. I ask questions that are typical of the problems I see in the real world.

I usually start with simple questions about how you analyze a small data set with lots of outliers. It's a gift of a question; anyone who's done analysis themselves will have come across the problem and will know the answer, it's easy. Many candidates give the wrong answers, with some giving crazily complex answers. Of course, sales and other business data often have small sample sizes and large outliers. 

My follow-up is usually something more complex. I sometimes ask about detecting bias in a data set. This requires some knowledge of probability distributions, confidence intervals, and statistical testing. Bear in mind, I'm not asking people to do calculations, I'm asking them how they would approach the problem and the methods they would use (again, it's OK if they forget the names of the methods). This problem is relevant because we sometimes need to detect whether there's an effect or not, for example, can we really increase sales through sales training? Once again, some candidates flounder and have no idea how to approach the problem.

Testing knowledge and insight

I sometimes ask how you would tell if two large, normally distributed data sets are different. This could be an internet A/B test or something similar. Some candidates ask how large the data set is, which is a good question; the really good candidates tell me why their question is important and the basis of it. Most candidates tell me very confidently that they would use the Student-t test, which isn't right but is a sort-of OK answer. I've happily accepted an answer along the lines of "I can't remember the exact name of the test, but it's not the Student-t. The test is for larger data sets and involves the calculation of confidence intervals". I don't expect candidates to have word-perfect answers, but I do expect them to tell me something about the methods they would use.

Often in business, we have problems where the data isn't normally distributed so I expect candidates to have some knowledge of non-normal distributions. I've asked candidates about non-normal distributions and what kind of processes give them. Sadly, a number of candidates just look blank. I've even had candidates who've just finished Master's degrees in statistics tell me they've only ever studied the normal distribution.

I'm looking for people who have a method toolkit but also have an understanding of the why underneath, for example, knowing why the Student-t test isn't a great answer for a large data set.

Data science != machine learning

I've found most candidates are happy to talk about the machine learning methods they've used, but when I've asked candidates why they used the methods they did, there's often no good answer. XGBoost and random forest are quite different and a candidate really should have some understanding of when and why one method might be better than another.

I like to ask candidates under what circumstances machine learning is the wrong solution and there are lots of good answers to this question. Sadly, many candidates can't give any answer, and some candidates can't even tell me when machine learning is a good approach.

Machine learning solves real-world problems but has real-world issues too. I expect candidates with postgraduate degrees, especially those with PhDs, to know something about real-world social issues. There have been terrible cases where machine learning-based systems have given racist results. An OK candidate should know that things like this have happened, a good candidate should know why, and a great candidate should know what that implies for business. 

Of course, not every data science problem is a machine learning problem and I expect all candidates at all levels to appreciate that and to know what that means.

Do you really have the skills you claim?

This is an issue for candidates with several years of business experience, but recent graduates have to watch out for it too. I've found that many people really don't have the skills they claim to have or have wildly overstated their skill level. I've had candidates claim extensive experience in running and analyzing A/B tests but have no idea about statistical power and very limited idea of statistical testing. I've also had candidates massively overstate their Python and SQL skills. Don't apply for technical positions claiming technical skills you really don't have; you should have a realistic assessment of your skill level.

Confidence != ability

This is more of a problem with experienced candidates but I've seen it with soon-to-be graduates too. I've interviewed people who come across as very slick and very confident but who've given me wildly wrong answers with total confidence. This is a dangerous combination for the workplace. It's one thing to be wrong, but it's far far worse to be wrong and be convincing.

To be fair, sometimes overconfidence comes from a lack of experience and a lack of exposure to real business problems. I've spoken to some recent (first-degree) graduates who seemed to believe they had all the skills needed to work on advanced machine learning problems, but they had woefully inadequate analysis skills and a total lack of experience. It's a forgivable reason for over-confidence, but I don't want to be the person paying for their naïveté.

Don't Google the answer

Don't tell me you would Google how to solve the problem. That approach won't work. A Google search won't tell you that not all count data is Poisson distributed or why variable importance is a useful concept. Even worse, don't try and Google the answer during the interview.

Don't be rude, naive, or stupid

A receptionist once told me that an interview candidate had been rude to her. It was an instant no for that candidate at that point. If you think other people in the workplace are beneath you, I don't want you on my team.

I remember sitting in lecture theaters at the start of the semester where students would ask question after question about the exams and what would be in them. I've seen that same behavior at job interviews where some candidates have asked an endless stream of questions about the process and what they'll be asked at what stage. They haven't realized that the world of work is not the world of education. None of the people who asked questions like this made it passed the first round or two, they just weren't ready for the work place. It's fine to ask one or two questions about the process, but any more than that shows naivete. 

I was recruiting data scientists fresh out of Ph.D. programs and one candidate, who had zero industrial experience, kept asking how quickly they could be promoted to a management position. They didn't ask what we were looking for in a manager, or the size of the team, or who was on it, but they were very keen on telling me they expected to be managing people within a few months. Guess who we didn't hire?

Be prepared

Be prepared for technical questions at any stage of the interview process. You might even get technical questions during HR screening. If someone non-technical asks you a technical question, be careful to answer in a way they can understand. 

Don't be surprised if questions are ambiguously worded. Most business problems are unclear and you'll be expected to deal with poorly defined problems. It's fine to ask for more details or for clarification.

If you forget the name of a method, don't worry about it. Talk through the principle and show you understand the underlying ideas. It's important to show you understand what needs to be done.

If you can, talk about what you've done and why you did it. For example, if you've done a machine learning project, use that as an example, making sure you explain why you made the project choices you did. Work your experience into your answers and give examples as much as you can.

Be prepared to talk about any technical skills you claim or any area of expertise. Almost all the people interviewing you will be more senior than you and will have done some of the same things you have. They may well be experts.

If you haven't interviewed in many places, or if you're out of practice, role-playing interviews should help. Don't choose people who'll go easy on you, instead chose people who'll give you a tough interview, ideally tougher than real-world interviews.

Most interviews are now done over Zoom. Make sure your camera is on and you're in a good place to do the interview.

Stand out in a good way

When you answer technical questions, be sure to explain why. If you can't answer the question, tell me what you do know. Don't just tell me you would use the Wilson score interval, tell me why you would use it. Don't just tell me you don't know how to calculate sample sizes, tell me how you would go about finding out and what you know about the process.

I love it when a candidate has a GitHub page showing their work. It's fine if it's mostly class projects, in fact, that's what I would expect. But if you do have a GitHub page, make sure there's something substantive there and that your work is high quality. I always check GitHub pages and I've turned down candidates if what I found was poor.

Very, very few candidates have done this, but if you have a writing sample to show, that would be great. A course essay would do, but obviously a great one. You could have your sample on your GitHub page. A writing sample shows you can communicate clearly in written English, which is an essential skill.

If you're a good speaker, try and get a video of you speaking up on YouTube and link it from your GitHub page (don't do this if you're bad or just average). Of course, this shows your ability to speak well.

For heaven's sake, ask good questions. Every interviewer should leave you time to ask questions and you should have great questions to ask. Remember, asking good questions is expected

What hiring managers want

We need people who:

  • have the necessary skills
  • will be productive quickly
  • need a minimal amount of hand-holding
  • know the limitations of their knowledge and who we can trust not to make stupid mistakes
  • can thrive in an environment where problems are poorly defined
  • can work with the rest of the team.

Good luck.

Monday, November 28, 2022

Is this coin biased?

Tossing and turning

A few months ago, someone commented on one of my blog posts and asked how you work out if a coin is biased or not. I've been thinking about the problem since then. It's not a difficult one, but it does bring up some core notions in probability theory and statistics which are very relevant to understanding how A/B testing works, or indeed any kind of statistical test. I'm going to talk you through how you figure out if a coin is biased, including an explanation of some of the basic ideas of statistical tests.

The trial

A single coin toss is an example of something called a Bernoulli trial, which is any kind of binary decision you can express as a success or failure (e.g. heads or tails). For some reason, most probability texts refer to heads as a success. 

We can work out what the probability is of getting different numbers of heads from a number of tosses, or more formally, what's the probability \(P(k)\) of getting \(k\) heads from \(n\) tosses, where \(0 < k ≤ n\)? By hand, we can do it for a few tosses (three in this case):

 Number of heads (k) Combinations (n)  Count  Probability 
 0 TTT 1 1/8
 1 HTT
 THT
 TTH
 3 3/8 
 2 THH
 HTH
 HHT
 3  3/8
 4 HHH 1 1/8

But what about 1,000 or 1,000,000 tosses - we can't do this many by hand, so what can we do? As you might expect, there's a formula you can use: 
\[P(k) = \frac{n!} {k!(n-k)!} p^k (1-p)^{n-k}\]
\(p\) is the probability of success in any trial, for example, getting a head. For an unbiased coin \(p=0.5\); for a coin that's biased 70% heads \(p=0.7\). 

If we plot this function for an unbiased coin (\(p=0.5\)), where \(n=100\), and \(0 < k ≤ n\), we see this probability distribution:

This is called a binomial distribution and it looks a lot like the normal distribution for large (\(> 30\)) values of \(n\). 

I'm going to re-label the x-axis as a score equal to the fraction of heads: 0 means all tails, 0.5 means \(\frac{1}{2}\) heads, and 1 means all heads. With this slight change, we can more easily compare the shape of the distribution for different values of \(n\). 

I've created two charts below for an unbiased coin (\(p=0.5\)), one with \(n=20\) and one with \(n=40\). Obviously, the \(n=40\) chart is narrower, which is easier to see using the score as the x-axis. 

As an illustration of what these charts mean, I've colored all scores 0.7 and higher as red. You can see the red area is bigger for \(n=20\) than \(n=40\). Bear in mind, the red area represents the probability of a score of 0.7 or higher. In other words, if you toss a fair coin 20 times, you have a 0.058 chance of seeing a score of 0.7 or more, but if you toss a fair coin 40 times, the probability of seeing a 0.7 score drops to 0.008.


These charts tell us something useful: as we increase the number of tosses, the curve gets narrower, meaning the probability of getting results further away from \(0.5\) gets smaller. If we saw a score of 0.7 for 20 tosses, we might not be able to say the coin was biased, but if we got a score of 0.7 after 40 tosses, we know this score is very unlikely so the coin is more likely to be biased.

Thresholds

Let me re-state some facts:

  • For any coin (biased or unbiased) any score from 0 to 1 is possible for any number of tosses.
  • Some results are less likely than others; e.g. for an unbiased coin and 40 tosses, there's only a 0.008 chance of seeing a score of 0.7.

We can use probability thresholds to decide between biased and non-biased coins.  We're going to use a threshold (mostly called confidence) of 95% to decide if the coin is biased or not. In the chart below, the red areas represent 5% probability, and the blue areas 95% probability.

Here's the idea to work out if the coin is biased. Set a confidence value, usually at 0.05. Throw the coin \(n\) times, record the number of heads and work out a score. Draw the theoretical probability chart for the number of throws (like the one I've drawn above) and color in 95% of the probabilities blue and 5% red. If the experimental score lands in the red zones, we'll consider the coin to be biased, if it lands in the blue zone, we'll consider it unbiased.

This is probabilistic decision-making. Using a confidence of 0.05 means we'll wrongly say a coin is biased 5% of the time. Can we make the threshold higher, could we use 0.01 for instance? Yes, we could, but the cost is increasing the number of trials.

As you might expect, there are shortcuts and we don't actually have to draw out the chart. In Python, you can use the binom_test function in the stats package. 

To simplify, binom_test has three arguments:

  • x - the number of successes
  • n - the number of samples
  • p - the hypothesized probability of success
It returns a p-value which we can use to make a decision.

Let's see how this works with a confidence of 0.05. Let's take the case where we have 200 coin tosses and 140 (70%) of them come up heads. We're hypothesizing that the coin is fair, so \(p=0.5\).

from scipy import stats
print(stats.binom_test(x=140, n=200, p=0.5))

the p-value we get is 1.5070615573524992e-08 which is way less than our confidence threshold of 0.05 (we're in the red area of the chart above). We would then reject the idea the coin is fair.

What if we got 112 heads instead?

from scipy import stats
print(stats.binom_test(x=115, n=200, p=0.5))

This time, the p-value is 0.10363903843786755, which is greater than our confidence threshold of 0.05 (we're in the blue area of the chart), so the result is consistent with a fair coin (we fail to reject the null).

What if my results are not significant? How many tosses?

Let's imagine you have reason to believe the coin is biased. You throw it 200 times and you see 115 heads. binom_test tells you you can't conclude the coin is biased. So what do you do next?

The answer is simple, toss the coin more times.

The formulae for the sample size, \(n\), is:

\[n = \frac{p(1-p)} {\sigma^2}\]

where \(\sigma\) is the standard error. 

Here's how this works in practice. Let's assume we think our coin is just a little biased, to 0.55, and we want the standard error to be \(\pm 0.04\). Here's how many tosses we would need: 154. What if we want more certainty, say \(\pm 0.005\), then the number of tosses goes up to 9,900. In general, the bigger the bias, the fewer tosses we need, and the more certainty we want the more tosses we need. 

If I think my coin is biased, what's my best estimate of the bias?

Let's imagine I toss the coin 1,000 times and see 550 heads. binom_test tells me the result is significant and it's likely my coin is biased, but what's my estimate of the bias? This is simple, it's actually just the mean, so 0.55. Using the statistics of proportions, I can actually put a 95% confidence interval around my estimate of the bias of the coin. Through math I won't show here, using the data we have, I can estimate the coin is biased 0.55 ± 0.03.

Is my coin biased?

This is a nice theoretical discussion, but how might you go about deciding if a coin is biased? Here's a step-by-step process.

  1. Decide on the level of certainty you want in your results. 95% is a good measure.
  2. Decide the minimum level of bias you want to detect. If the coin should return heads 50% of the time, what level of bias can you live with? If it's biased to 60%, is this OK? What about biased to 55% or 50.5%?
  3. Calculate the number of tosses you need.
  4. Toss your coin.
  5. Use binom_test to figure out if the coin deviates significantly from 0.5.

Other posts like this